直接在 html 里限制就可以了,上代码:
<input type="text" placeholder="只能输入数字" onkeyup="this.value = this.value.replace(/\D/,'')" >