2014-03-19 297 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

相關問題