jQuery函数
//文本框只能输入数字(包括小数),并屏蔽输入法和粘贴
jQuery.fn.number=function(){
this.bind("keypress",function(e){
var code=(e.keyCode?e.keyCode:e.which); //兼容火狐 IE
//火狐下不能使用退格键
if(!$.browser.msie&&(e.keyCode==0x8)){return;}
if(this.value.indexOf(".")==-1){
return (code >= 48 && code<= 57)||(code==46);
}
else{
return code >= 48 && code<= 57}
});
this.bind("paste",function(){return false;});
this.bind("keyup",function(){
if(this.value.slice(0,1) == "."){
this.value = "";
}
$(this).val($(this).val().replace(/[^0-9.]/g,'')); //限制输入除数字和“.”外的其他字符
});
this.bind("blur",function(){
if(this.value.slice(-1) == ".")
{
this.value = this.value.slice(0,this.value.length-1);
}
});
};
调用生效:
$(function(){
$("#REGIST_FUND").number();
});