js限制用户只能输入数字

来源:互联网 发布:金山恢复数据在哪里 编辑:程序博客网 时间:2024/05/16 12:23
 rnumber : function(min){
this.keyup(function(){
            $(this).val($(this).val().replace(/[^0-9]/g,''));
            if(min != undefined && $(this).val().length == 0){
            $(this).val(min);
            }
        }).bind("paste",function(){                                                             //CTR+V事件处理
            $(this).val($(this).val().replace(/[^0-9]/g,''));
            if(min != undefined && $(this).val().length == 0){
            $(this).val(min);
            }
        }).css("ime-mode", "disabled").bind("contextmenu",function(e){   //限制用户右键
              return false;
        });
return this;
}

原创粉丝点击