[英]Use javascript onblur event to default input box to 0.00 if no value is entered or if a value is less than 0
Here is my onblur event with the javascript so far.到目前为止,这是我使用 javascript 的 onblur 事件。 There are values auto loaded into the box on the page load but if a user deletes the value or enters a value less than zero it should default to 0.00.在页面加载时自动加载到框中的值,但如果用户删除该值或输入小于零的值,则默认为 0.00。 Right now it is defaulted to NaN.现在它默认为 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)">
Use the following funtion for IsNaN control.使用以下函数进行 IsNaN 控制。
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
New Code新代码
function checkformat(entry) {
test = entry.value;
if (isNumeric(test)) {
entry.value=parseFloat(test).toFixed(2);
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.