Copy codeThe Code is as follows:
$ (Function (){
// Only numbers (excluding decimals) can be entered in the text box, and the input method and pasting are blocked.
$. Fn. integer = function (){
Certificate (this).css ("ime-mode", "disabled ");
This. bind ("keypress", function (e ){
Var code = (e. keyCode? E. keyCode: e. which); // compatible with Firefox IE
If (! $. Browser. msie & (e. keyCode = 0x8) {// you cannot use the backspace key under Firefox.
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 */,'');
}
});
};
// Only numbers (including decimals) can be entered in the text box, and the input method and pasting are blocked.
$. Fn. number = function (){
Certificate (this).css ("ime-mode", "disabled ");
This. bind ("keypress", function (e ){
Var code = (e. keyCode? E. keyCode: e. which); // compatible with Firefox IE
If (! $. Browser. msie & (e. keyCode = 0x8) {// you cannot use the backspace key under Firefox.
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 );
}
});
};
});