使 html input 标签只能输入数字

时间:2022-11-05 11:38:40
其中,使用了JS技术,此时,input 框只接受数字键,其他按键均不起作用
<script type="text/javascript">
function IsNum(ev) {
var key = window.event ? ev.keyCode : ev.which;
if (((key >= 48) && (key <= 57)) || k === 8 || k === 0) {
} else {
if (window.event) {
window.event.returnValue = false;
}
else {
ev.preventDefault(); //for firefox
}
}
}
</script>

<input style="IME-MODE: disabled;" value="1" name="num" onkeypress = "return IsNum(event)">