繁体   English   中英

单击按钮时,关闭模态表单并打开一个新表单

[英]Closing Modal Form and Opening a New One When Button is Clicked

因此,我正在为学校项目建立一个网站,但似乎在某个部分遇到了麻烦。 我有一个注册链接,以便用户可以注册成为该网站的成员。 单击注册链接后,将在屏幕中间弹出一个模式表单,用户可以在其中将数据输入到特定字段中。 完成此操作后,他们单击页面底部的提交按钮“转到”。 这将触发另一个模态形式弹出,显示“感谢您注册Dominion Luxury Cars”。 右上角有一个X,当他们单击它时,我注意到Sign modal表单仍然打开。 我试图这样做,以便在单击“开始”按钮时关闭“注册”模式表单。 到目前为止,关闭“注册”模式表单的唯一方法是单击右上角的X。 我也想保留这个。 基本上,我希望在单击X或单击“转到”按钮时关闭“注册”模式表单,如果单击“转到”按钮,我希望模式表单显示“谢谢您注册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 = '';
}

只需添加

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

到您的openConfirm()函数。

工作小提琴

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

工作小提琴

或者只是调用您的函数closeSignUp(); 在您的函数openConfirm()

工作小提琴

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

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

工作jsfiddle。 它没有用,因为您具有用于“执行onLoad”的javascript设置,因此您的函数被包装在事件处理程序中,并且不是全局的。 我改了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM