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