更大我要驗證這個javascript函數如果一個數比另一個數的JavaScript,如果數量超過數
function validateForm() {
var x = document.forms["frmOrder"]["txtTotal"].value;
var y = document.forms["frmOrder"]["totalpoints"].value;
if (x > y) {
alert("Sorry, you don't have enough points");
return false;
}
}
這不是出於某種原因的工作更大。
如果我做alert(x)
我得到1300和alert(y)
給999
這個工程....
function validateForm() {
var x = 1300;
var y = 999;
if (x > y) {
alert("Sorry, you don't have enough points");
return false;
}
}
您正在比較字符串,而不是數字。 –
@ user1689607比較數字字符串仍然有效,即「5」>「2」// true' –
@MattStone:'「1300」>「999」; // false' –