[英]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不會彈出該表格,但是我知道該代碼的工作原理后,您可以將其發布到文本編輯中以進行測試。
//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 = '';
}
你擁有一切。 您唯一需要做的就是修改Go
按鈕的onclick
處理程序:
<button type="submit" onClick="openConfirm(); closeSignUp();">Go</button>
工作jsfiddle。 。 它沒有用,因為您具有用於“執行onLoad”的javascript設置,因此您的函數被包裝在事件處理程序中,並且不是全局的。 我改了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.