为了账号安全,请及时绑定邮箱和手机立即绑定

无法在JQuery中检查多个if else条件

无法在JQuery中检查多个if else条件

慕的地8271018 2021-04-06 04:28:23
我正在尝试在JQuery中检查某些多个条件,但未返回所需的结果。无论我输入什么,它总是进入其他条件。$(function() {  $('#installment').on("keydown keyup", check);  function check() {    var inst = Number($("#installment").val());    if (inst === 2 || inst === 4 || inst === 6 || inst === 12) {      return true;    } else {      $("#installment").val('');      alert("you can not set wrong value");      return false;    }  }});<script src="https://code.jquery.com/jquery-3.3.1.js"></script><tr>  <td>Number of Installment</td>  <td><input type="text" name="installment" id="installment"></td></tr>
查看完整描述

3 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

$(function() {

    var val = $("#installment").val();

  $('#installment').on("keydown keyup",

  function () {

    var inst = Number($("#installment").val());

    if (inst === 2 || inst === 4 || inst === 6 || inst === 12) {

      alert("OK");

     return false;

    } else {

      $("#installment").val('');

      alert("you can not set wrong value");

      //return false;

    }

  });

});


查看完整回答
反对 回复 2021-04-08
  • 3 回答
  • 0 关注
  • 188 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号