【发布时间】:2020-09-09 01:54:31
【问题描述】:
我需要创建一个只接受数字的输入。为此,我创建了一个文本类型的输入,并且只接受 5 位长度。
<input id="inputNumber" type="text" maxlength="5">
为了只接受数字,我创建了如下的 jquery 代码。
$("#inputNumber").keypress(function (value) {
// If the letter is not digit then display error and don't type anything
if (value.which != 8 && value.which != 0 && (value.which < 48 || value.which > 57)) {
return false;
}
else {
return true;
}
});
我尝试将其转换为我的 Type 脚本文件的 AddEventListner 但失败了。我什至尝试了下面的方法,但又失败了。我该如何解决这个问题。
参考:keypress event doesn't log input value first time event is fired
【问题讨论】:
标签: javascript jquery typescript visual-studio asp.net-core