復制代碼 代碼如下:
 
$(function(){ 
//文本框只能輸入數字(不包括小數),并屏蔽輸入法和粘貼 
$.fn.integer= function() { 
$(this).css("ime-mode", "disabled"); 
this.bind("keypress",function(e) { 
var code = (e.keyCode ? e.keyCode : e.which); //兼容火狐 IE 
if(!$.browser.msie&&(e.keyCode==0x8)){ //火狐下不能使用退格鍵 
return ; 
} 
return code >= 48 && code<= 57; 
}); 
this.bind("paste", function() { 
return false; 
}); 
this.bind("keyup", function() { 
if (/(^0+)/.test(this.value)) { 
this.value = this.value.replace(/^0*/, ''); 
} 
}); 
}; 
//文本框只能輸入數字(包括小數),并屏蔽輸入法和粘貼 
$.fn.number= function() { 
$(this).css("ime-mode", "disabled"); 
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.bind("blur",function(){ 
if(this.value.slice(-1) == "."){ 
this.value = this.value.slice(0,this.value.length-1); 
} 
}); 
}; 
}); 
新聞熱點
疑難解答
圖片精選