Several Basic Methods for extending jQuery Keyboard Events _ jquery

Source: Internet
Author: User
Several Basic Methods for extending jQuery Keyboard Events (Exercise jQuery plugin extension) File Name: jquery. hy. key. js

The 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:

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:

*/
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;
}
});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.