简体   繁体   English

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

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

So I am building a website for school project but seem to be having some trouble with one section. 因此,我正在为学校项目建立一个网站,但似乎在某个部分遇到了麻烦。 I have a sign up link so that users can sign up to become a member of the site. 我有一个注册链接,以便用户可以注册成为该网站的成员。 Once the sign up link is clicked a modal form pops up in the middle of the screen where the user inputs data into specific fields. 单击注册链接后,将在屏幕中间弹出一个模式表单,用户可以在其中将数据输入到特定字段中。 Once they have done this they click a submit button "Go" at the bottom of the page. 完成此操作后,他们单击页面底部的提交按钮“转到”。 This triggers another modal form to pop up saying "Thank you for registering to Dominion Luxury Cars". 这将触发另一个模态形式弹出,显示“感谢您注册Dominion Luxury Cars”。 There is an X in the top right corner and once they click it I noticed the Sign Up modal form was still open. 右上角有一个X,当他们单击它时,我注意到Sign modal表单仍然打开。 I am trying to make it so that when the "Go" button is clicked the Sign Up modal form closes. 我试图这样做,以便在单击“开始”按钮时关闭“注册”模式表单。 As of now the only way the Sign Up modal form closes is when the X in the top right corner is clicked. 到目前为止,关闭“注册”模式表单的唯一方法是单击右上角的X。 I want to retain this as well. 我也想保留这个。 Basically I want the Sign Up modal form to close either when the X is clicked or the "Go" button is clicked and if the "Go" button is clicked I want the modal form saying "Thank you for registering to Dominion Luxury Cars" to appear. 基本上,我希望在单击X或单击“转到”按钮时关闭“注册”模式表单,如果单击“转到”按钮,我希望模式表单显示“谢谢您注册Dominion Luxury Cars”出现。

Thank you anyone who is able to help me out. 谢谢任何能够帮助我的人。 I really appreciate it. 我真的很感激。

BELOW IS A JSFIDDLE VERSION OF MY CODE FOR SOME REASON THE FORM DOES NOT POP UP USING JSFIDDLE HOWEVER I KNOW THE CODE WORKS YOU CAN POST IT INTO TEXT EDIT FOR TESTING PURPOSES. 以下是我的代码的JSFIDDLE版本,出于某种原因,使用JSFIDDLE不会弹出该表格,但是我知道该代码的工作原理后,您可以将其发布到文本编辑中以进行测试。

http://jsfiddle.net/3cjbf/ 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 = '';
}

Just add 只需添加

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

to your openConfirm() function. 到您的openConfirm()函数。

Working Fiddle 工作小提琴

Or alternatively add document.getElementsByClassName('modalSignUp')[0].id = ''; 或者添加document.getElementsByClassName('modalSignUp')[0].id = ''; like you have it in your closeSignUp() function. 就像在closeSignUp()函数中使用它一样。

Working Fiddle 工作小提琴

Or just call your function closeSignUp(); 或者只是调用您的函数closeSignUp(); within your function openConfirm() . 在您的函数openConfirm()

Working Fiddle 工作小提琴

You had everything. 你拥有一切。 The only thing you need is to modify the onclick handler of your Go button: 您唯一需要做的就是修改Go按钮的onclick处理程序:

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

Working jsfiddle. 工作jsfiddle。 . It didn't work because you had the javascript settings to 'execute onLoad', so your functions got wrapped in a event handler and were not global. 它没有用,因为您具有用于“执行onLoad”的javascript设置,因此您的函数被包装在事件处理程序中,并且不是全局的。 I changed it. 我改了

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

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