当输入框中的值过高时获得警报

  • 本文关键字:高时获 jquery
  • 更新时间 :
  • 英文 :


当用户输入的值大于1时,将出现一个警告。

这个行不通:

<input id="inputValue" type="text">
$(function () {
    $(document).ready(function () {
        $('#inputValue').keyup(function () {
            if ('#inputValue'.val()) > 1 alert('Value must be a decimal between 0 en 1');
        });
    });
})(jQuery);

你的代码有很多错误

试试这个

  $(document).ready(function () {
   $('#inputValue').keyup(function () {
        if ($(this).val() > 1 )
            alert('Value must be a decimal between 0 en 1');    
   });
  });

你的if语句不正确。

试题:

if ($(this).val()>1){
 alert("....");
}

检查if语句,发现遗漏了$.

if ($('#inputValue').val() > 1 ) {
            alert('Value must be a decimal between 0 en 1');
}

JSFiddle

最新更新