下面是我在 MVC
应用程序 View 中的文本框。
我希望当它加载时它具有默认值“0”并且只允许数字。那么它如何可能只使用一个常用功能。当用户将其保留为空白时,它会自动获取默认值。
@Html.TextBoxFor(model => item.myfeild, new { placeholder = "Required", @class = "myclass", require = "true", maxlength = "1", id = @item.myid })
最佳答案
Use This Function write event in textbox
onkeypress="return isNumberKey(event);"
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
关于javascript - 仅适用于数值的 javascript 函数,默认值 "0",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23951143/