2014-03-19 186 views
0

因此,我正在为学校项目构建一个网站,但似乎在某个部分有些麻烦。我有一个注册链接,以便用户可以注册成为该网站的成员。点击注册链接后,用户将数据输入到特定字段的屏幕中间弹出一个模式表单。一旦他们完成了这些,他们点击页面底部的提交按钮“开始”。这会触发另一种模式形式,弹出“感谢您注册Dominion豪华汽车”。在右上角有一个X,一旦他们点击它,我注意到注册模式表单仍处于打开状态。我试图做到这一点,当点击“开始”按钮时,注册模式窗体关闭。截至目前,注册模式表单关闭的唯一方法是点击右上角的X.我也想保留这个。基本上我希望注册模式表单可以在单击X或单击“Go”按钮时关闭,如果单击“Go”按钮,我希望模式表单显示“感谢您注册Dominion豪华汽车”以出现。关闭模式窗体并在点击按钮时打开一个新窗口

谢谢任何​​能够帮助我的人。对此,我真的非常感激。

下面是我的代码的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 = ''; 
} 

回答

0

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

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

工作jsfiddle.。它没有工作,因为你的JavaScript设置为'执行onLoad',所以你的函数被包装在一个事件处理程序中,而不是全局的。我改变了它。

+0

非常感谢你,它完美的工作,我不认为你可以在onClick命令中调用多个函数。 – Brandon

+0

你可以这样做,因为你在事件处理程序属性中放置的任何代码都被封装在窗帘后面的函数中。当然,这不是推荐的做法。你应该使用'addEventListener'或者像jQuery这样的辅助类库来附加事件处理程序。 –

0

只需添加

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

openConfirm()功能。

Working Fiddle

或者或者添加document.getElementsByClassName('modalSignUp')[0].id = '';就像你在你的closeSignUp()功能有它。

Working Fiddle

或者只是调用函数openConfirm()内的功能closeSignUp();

Working Fiddle

相关问题