[英]Allow only numbers to be typed in a textbox - default to zero
如何對此進行修改,以便如果用戶不輸入數字,那么將在文本字段中輸入數字0,在此先感謝您:
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
使用IsNumeric並檢查是否也為0。
IsNumeric(number goes here)
如果用戶未輸入數字,則將在文本字段中輸入0
<input type="text" id="numeric" value="0" onclick="this.value='' " onblur="if(this.value==''){ this.value='0'} " />
正則表達式僅用於數字。
$('#numeric').on('input', function (event) {
this.value = this.value.replace(/[^0-9]/g, '');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.