javascript - 用户单击输入类型复选框时进行条件检查

标签 javascript jquery if-statement

功能:

用户输入姓名和电子邮件以及可选的条件复选框。此复选框供用户检查是否已年满 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/

相关文章:

jquery - 正则表达式 jquery

jquery select2 : no matches found

javascript - 如何避免事件和悬停背景

c++ - 两平方和分解计数

mysql - 尝试创建一个带有参数并使用 if 语句的存储过程

javascript - 基于另一列填充 BootstrapTable x-可编辑选择框

javascript - 在 OpenLayers 3 上选择并突出显示我自己的绘图

c - 使用 C 编程语言对 XM1000 传感器设备进行编程 需要 if 语句

javascript - 自定义对象上的 Jquery on() 单击函数

javascript - 如何从 then block 内的 Promise 返回?