我試圖讓我的輸入字段只接受整數並寫了一些java來幫助驗證,但每次我單擊下一個輸入以插入值時,它都會發送我的警報。我錯過了什麼嗎?使用整數驗證數量
<script type="text/javascript">
var cartAmount, subtotal, pstAmount, pstTax, gstTax, taxAmount, shipCharge, afterTax;
function validate() {
//Whole Numbers with Regexp
var rx = new RegExp(/\d+/);
if(document.getElementsByClassName("inputValue").value != rx || document.getElementsByClassName("inputValue").value == "") {
alert("Please use only whole quantities.");
return false;
}
}
function sumCart() {
//Adding Cart Values
cartAmount = (document.frmMain.item1.value * 3.99) + (document.frmMain.item2.value * 5.99);
//Finding Subtotals
document.frmMain.subtotalAmt.value = Math.round(cartAmount*100)/100;
subtotal = document.frmMain.subtotalAmt.value;
//Finding Taxes
pstTax = document.frmMain.taxAmount.value;
gstTax = .05;
pstAmount = Math.round((subtotal * pstTax)*100)/100;
gstAmount = Math.round((subtotal * gstTax)*100)/100;
taxAmount = parseFloat(pstAmount,10) + parseFloat(gstAmount,10);
document.getElementById("tax").innerHTML = "Tax in dollars is $" + Math.round(taxAmount * 100)/100;
//Finding Total
shipCharge = 0;
afterTax = parseFloat(subtotal) + parseFloat(taxAmount) + parseFloat(shipCharge);
document.frmMain.totalAmt.value = Math.round(afterTax*100)/100;
}
</script>
爲了我們每天都在做你的工作,報酬或報酬的回報在哪裏? – Jay
Java!= Javascript – Barmar
它不是每一天... – Xero1