2013-06-05 49 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