选中复选框后输入功能,输入值超过1000

时间:2017-08-07 11:41:17

标签: jquery

现在,我正在尝试为赌博网站csgopolygon.com创建一个脚本,并希望添加不允许您下注超过1000个筹码的功能。我希望它将betAmount输入中的值设置为1000,如果选中启用AntiGreed的复选框,并且用户在输入中使用标识为betAmount的数字写入超过1000的数字。这是我到目前为止所得到的:

$("#betAmount").keydown(function () {
if($('#antigreedcheck').is(':checked')){
    if(parseInt($("#betAmount").val()) > 1000) {
        $("#betAmount").val('1000');
    }
}
});

$("body").append('<div class="modal fade" id="settingsscript">'+
            '  <div class="modal-dialog">'+
            '   <div class="modal-content">'+
            '           <div class="modal-header">'+
            '           <button type="button" class="close" data-dismiss="modal">X</button>'+
            '           <h4 class="modal-title"><b><center><a href="http://bytec0.de">bytec0de&#039;s</a> csgopolygon script</center></b></h4>'+
            '           <h5 class="modal-title"><center>Win monies easily!</center></h5><br><br><br>'+
            '           <center><input type="checkbox" id="antigreedcheck"></input>'+
            '           <label for="antigreedcheck">AntiGreed</label><br></center>'+
            '           <center><button type="button" class="btn btn-danger" data-dismiss="modal">Close</button></center>'+
            '        </div>'+
            '   </div>'+
            '  </div>'+
            '</div>');

$("div .input-btn").append('<div id="setcolor2"></div><br><b><a href="#" style="font-size: 2em;" data-toggle="modal" data-target="#settingsscript"> Settings</a></b></div></div>');

此代码似乎不起作用,因为每次勾选复选框并在betAmount输入中输入超过1000时,它都不会执行任何操作。

2 个答案:

答案 0 :(得分:0)

您在# #betAmount遗失 $("#betAmount").keyup(function () { if($('#antigreedcheck').is(':checked')){ if(parseInt($("#betAmount").val()) > 1000){ $("#betAmount").val(1000); } }

{{1}}

答案 1 :(得分:0)

需要将keydown转换为keyup ,并添加丢失的#{工作得很好。

检查以下内容: -

$("#betAmount").keyup(function () {
  if($('#antigreedcheck').is(':checked')){ //# missing
      if(parseInt($("#betAmount").val()) > 1000){ //# missing and { missing too
          $("#betAmount").val(1000);
      }
  }
});

工作示例: -

&#13;
&#13;
$("#betAmount").keyup(function () {
  if($('#antigreedcheck').is(':checked')){ //# missing
      if(parseInt($("#betAmount").val()) > 1000){ //# missing and { missing too
          $("#betAmount").val(1000);
      }
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="antigreedcheck"/>
<br><br>
<input type="text" id="betAmount"/>
&#13;
&#13;
&#13;