File Name: jquery. hy. key. js
Copy codeThe Code is as follows:
/* ===================================================== ========================================================== =
Desc: Method for extending Keyboard Events
Called:
Auth: big weather
Date: 2009-10-30
========================================================== ==========================================================
Change History
========================================================== ==========================================================
Date: Author: Description:
-----------------------------------
========================================================== ==========================================================
Copyright (C) 1992-2009 Hongye Corporation
========================================================== ==========================================================
Prerequisites
1. number 0 key value 48 .. number 9 key value 57
2. a key value 97 .. z key value 122; A key value 65 .. Z key value 90
3. + key value 43;-key value 45;. Key Value 46; return 8; tab key value 9;
4. The event is global in ie and is a temporary object in firefox. parameters must be passed.
*/
JQuery. extend ({
/* ===================================================== ============================================
Function Description: Obtain the key value.
Call method:
JQuery. getKeyNum (event );
*/
GetKeyNum: function (e ){
Var keynum;
If (window. event) {// IE
Keynum = event. keyCode;
}
Else if (e. which) {// Netscape/Firefox/Opera
Keynum = e. which;
}
Return keynum;
},
/* ===================================================== ============================================
Function Description: determines whether it is an integer. You can only enter numbers in the edit box.
Call method:
<Input type = "text" onkeypress = "return jQuery. isInt (event);"/>
Problem to be resolved:
The tab key in firefox does not work.
*/
IsInt: function (e ){
Var keynum = this. getKeyNum (e );
If (keynum> = 48 & keynum <= 57 | keynum = 8) {// you need to judge 8 for the backspace in firefox.
Return true;
}
Return false;
},
/* ===================================================== ============================================
Function Description: determines whether it is a decimal number. You can only enter a number in the edit box and only one decimal point.
Call method:
<Input type = "text" onkeypress = "return jQuery. isFloat (this, event);"/>
*/
IsFloat: function (txt, e ){
Var keynum = this. getKeyNum (e );
If (keynum = 46) {// enter the decimal point
If (txt. value. length = 0 ){
Return false;
} Else if (txt. value. indexOf ('.')> = 0 ){
Return false;
} Else {
Return true;
}
}
If (this. isInt (e )){
Return true;
}
Return false;
}
});