单击按钮时关闭模态窗体并打开新窗体

时间:2014-03-19 15:57:25

标签: javascript html css forms modal-dialog

所以我正在为学校项目建立一个网站,但似乎在一个部分遇到了一些麻烦。我有一个注册链接,以便用户可以注册成为该网站的成员。单击注册链接后,屏幕中间会弹出一个模式窗体,用户将数据输入到特定字段中。完成后,他们点击一个提交按钮" Go"在页面的底部。这会触发另一种模式形式弹出说"感谢您注册Dominion Luxury Cars"。右上角有一个X,一旦点击它我注意到注册模式表格仍然打开。我试图让它成为当" Go"点击按钮关闭注册模式表单。截至目前,注册模式窗体关闭的唯一方法是单击右上角的X.我也希望保留这一点。基本上我希望注册模式表单在单击X或者" Go"时关闭。单击按钮,如果" Go"单击按钮我想要模态表单"感谢您注册Dominion Luxury Cars"出现。

谢谢任何有能力帮助我的人。我真的很感激。

以下是我的代码的JSFIDDLE版本,但由于我知道代码的工作原理,您可以将其发布到用于测试目的的文本编辑中,因此表格不会弹出使用JSFIDDLE。

http://jsfiddle.net/3cjbf/

//HTML CODE

<li><a href="#" onClick="openSignUp()">Sign-Up</a>
</li>
<div class="modalSignUp">
    <div>
        <table>
            <tr>
                <td>
                    <input type="text" placeholder="First Name" />
                </td>
                <td>
                    <input type="text" placeholder="Last Name" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" placeholder="E-mail" />
                </td>
                <td>
                    <input type="text" placeholder="Phone Number" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" placeholder="Street Address" />
                </td>
                <td>
                    <input type="text" placeholder="City" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" placeholder="State" />
                </td>
                <td>
                    <input type="text" placeholder="Zip Code" />
                </td>
            </tr>
        </table>
        <div class="newsletter">
            <input type="checkbox" />Subscribe to Dominion Luxury Cars News Letter?
            <br />
            <button type="submit" onClick="openConfirm()">Go</button> <a onclick="closeSignUp()" class="close">X</a>

        </div>
    </div>
</div>
<div class="modalConfirm">
    <div>
        <p>Thank you for registering for Dominion Luxury Cars</p> <a onclick="closeConfirm()" class="close">X</a>

    </div>
</div>

// CSS CODE

/********************************************************************************************************************/

/*Designing Modal Forms*/

/********************************************************************************************************************/
 #target {
    opacity:1;
    pointer-events: auto;
}
.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: -12px;
    text-align: center;
    top: -10px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}
.close:hover {
    background: #000000;
}
/********************************************************************************************************************/

/*Style Modal SignUp*/

/********************************************************************************************************************/
 .modalSignUp {
    position:fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 99999;
    opacity:0;
    -webkit-transition: opacity 400ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    transition: opacity 400ms ease-in;
    pointer-events: none;
}
.modalSignUp > div {
    width: 300px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
    height:250px;
}
.modalSignUp table {
    margin-left:2%;
    margin-top:10%;
    width:100%;
}
.modalSignUp button {
    float:right;
    margin-right:8px;
}
.signuplogo {
    margin-left:35%;
}
.newsletter {
    width:285px;
    height:20px;
    margin-left:auto;
    margin-right:auto;
    font-size:10px;
}
/********************************************************************************************************************/

/*Style Modal Confirm*/

/********************************************************************************************************************/
 .modalConfirm {
    position:fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 99999;
    opacity:0;
    pointer-events: none;
}
.modalConfirm > div {
    width: 300px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
    height:250px;
}
.modalConfirm p {
    margin-top:50px;
    text-align:center;
}

//JAVASCRIPT

function openSignUp() {
    document.getElementsByClassName('modalSignUp')[0].id = 'target';
}

function closeSignUp() {
    document.getElementsByClassName('modalSignUp')[0].id = '';
}

function openConfirm() {
    document.getElementsByClassName('modalConfirm')[0].id = 'target';
}

function closeConfirm() {
    document.getElementsByClassName('modalConfirm')[0].id = '';
}

2 个答案:

答案 0 :(得分:0)

添加

document.getElementsByClassName('modalSignUp')[0].style.display = 'none';

到您的openConfirm()功能。

Working Fiddle

或者添加document.getElementsByClassName('modalSignUp')[0].id = '';,就像在closeSignUp()函数中一样。

Working Fiddle

只需在您的函数closeSignUp();中调用您的函数openConfirm()

Working Fiddle

答案 1 :(得分:0)

你拥有一切。您唯一需要修改onclick按钮的Go处理程序:

<button type="submit" onClick="openConfirm(); closeSignUp();">Go</button>

工作jsfiddle.。它没有用,因为你有javascript设置来执行onLoad&#39;所以你的函数被包装在事件处理程序中并且不是全局的。我改变了它。

相关问题