如何限制input只能输入数字

在input上增加onkeyup和onafterpaste事件,事件中用正则表达式替换其它字符,测试没有问题。

<input type="text" value="" id="num" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"/>

posted @ 2015-08-31 14:15  zhjahch  阅读(1544)  评论(0编辑  收藏  举报