2013-06-05 102 views
1

当用户输入的值大于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); 
+0

你尝试检查您的控制台? (我已经知道了答案) – lifetimes

+0

你的代码中有语法错误。查看Chrome开发人员工具中的错误,或者在语法检查编辑器(如Komodo Edit)中加载代码以查看错误。 –

回答

2

你有很多错误的代码

试试这个

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

即将说出同样的话。 +1 – vdbuilder

1

你的if语句是不正确。

尝试:

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

检查您的if语句,你错过了$。

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

} 

JSFiddle