在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,'')"/>

发表评论