我想验证价格字段。我正在试试这个:isFinite的空间给出真实值
var productId = document.getElementById("productId");
var productName = document.getElementById("productName");
var productPrice = document.getElementById("price");
alert(isFinite(productPrice.value));
if(isNaN(productPrice.value)||!isFinite(productPrice.value)){
error = document.getElementById("priceError");
error.innerHTML = "Please enter correct value";
productPrice.style.border="thin solid red";
}else{
error = document.getElementById("priceError");
error.innerHTML = "";
}
只有当输入是空格/多个空格时,行警告才会让我真实。 这是我的HTML页面。
<td>Price</td>
<td><input type = "text" id = "price" size = "14"/></td>
感谢
你有什么在'productPrice.value'? – mishik
任何_String_的isFinite,其中'+ string'不是'+'/'-''Infinity'或'NaN'将是'true'。 –
@mishik:编辑 – NewUser