[英]How can I make this javascript function to allow more than 1 value to be entered into a input box with separated by a space?
[英]Use javascript onblur event to default input box to 0.00 if no value is entered or if a value is less than 0
到目前為止,這是我使用 javascript 的 onblur 事件。 在頁面加載時自動加載到框中的值,但如果用戶刪除該值或輸入小於零的值,則默認為 0.00。 現在它默認為 NaN。
function checkformat(entry) { test = entry.value; if (!isNaN(test)) { entry.value=parseFloat(entry.value).toFixed(2); } else if (isNaN(test) == true) { test.value='0.00'; } else if (test < 0.00) { test.value = '0.00'; } else { test.value = '0.00'; } }
<input id='Line Item <% line %>' type="text" onkeyup="updateTotal()" placeholder="Amount" name="AmountPaying" class="field m w-input" value="<% r.AmountOwed %>" onblur="checkformat(this)">
使用以下函數進行 IsNaN 控制。
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
新代碼
function checkformat(entry) {
test = entry.value;
if (isNumeric(test)) {
entry.value=parseFloat(test).toFixed(2);
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.