input框只能输入数字

来源:互联网 发布:网络教学平台官网 编辑:程序博客网 时间:2024/05/18 09:19

只能输入正整数
1、方法一:

<input type="text" onkeyup="checkRem(this)">
 function checkRem(This) {      This.value = This.value.replace(/[^\d]/g, '');  }

2、方法二:

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

只能输入数字或者小数
1、方法一:

<input type="text" onkeyup="checkRem(this)">
 function checkRem(This) {      This.value = This.value.replace(/[^\d.]/g, '');  }

2、方法二:

<input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')"/>

3、jquery

$("input[type='text']").keyup(function () {        var $this = $(this);        var val = $this.val().replace(/[^\d]/g, '');        $this.val(val);    });
0 0
原创粉丝点击