功能:
用户输入姓名和电子邮件以及可选的条件复选框。此复选框供用户检查是否已年满 18 岁。
因此,如果用户选中该框以表明其年龄超过 18 岁,并且当用户单击“提交”时,该页面会将用户导航到页面 A。否则,如果用户未选中该框,该页面会将用户导航到页面 A B.
<小时/>问题:
此时,我只知道必须使用条件 if...else
语句来进行检查并允许正确的函数调用。但是,当用户单击提交按钮执行条件检查后,我绝对不知道如何从头开始进行。因此,我确实请求一些帮助来帮助我开始。
谢谢
<小时/>代码:
<div id="EmailPage" align="center" style="position:absolute; height: 1080px; width:1920px; background-repeat: no-repeat; display: none; z-index=7; top:0px; left:0px; ">
<!--Email Buttons-->
<table align="center" cellspacing="0" cellpadding="0" width="1080" top="550px">
<tr style="height: 1920;">
<td width="1080">
<input type="text" id="NameField" style="z-index=8; position:absolute; top:273px; left:779px; height:53px; width:511px; outline= 0; border: 0; font-size:25px; font-family:'CenturyGothic'; background: transparent;">
<input type="text" id="EmailField" style="z-index=8; position:absolute; top:342px; left:779px; height:53px; width:511px; outline=0; border: 0; font-size:25px; font-family:'CenturyGothic'; background: transparent;">
<input type="checkbox" id="AcknowledgeField" style="z-index=8; position:absolute; top:428px; left:776px; height:22px; width:24px; outline=0; border: 0; background: transparent;">
<button id="Submit" onclick="Submit()">
</button>
</td>
</tr>
</table>
</div>
最佳答案
既然您已经包含了 JQuery。这是你可以使用的东西。
<script>
$(document).ready(function(e) {
$(document).on('click','#Submit', function(){
/////test if check box is check
if ($('#AcknowledgeField').is(':checked')){
alert("About to go to pageA");
window.location.href="../pageA.html";
} else {
///////cheeck box not checked///////////
alert("About to go to pageA");
window.location.href="../pageB.html";
}
})
});
</script>
关于javascript - 用户单击输入类型复选框时进行条件检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35462656/