Home  >  Article  >  Web Front-end  >  Several basic methods to extend jQuery keyboard events_jquery

Several basic methods to extend jQuery keyboard events_jquery

WBOY
WBOYOriginal
2016-05-16 18:42:51949browse

File name: jquery.hy.key.js

Copy code The code is as follows:

/* ================================================== ==============================
Desc: Extended method for keyboard events

Called by:

Auth: Big weather
Date: 2009-10-30
============================ ================================================== ===
Change History
========================================== =========================================
Date: Author: Description:
-------- -------- -------------------

====== ================================================== ========================
Copyright (C) 1992-2009 Hongye Corporation
============ ================================================== ===================

Preliminary knowledge
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; backspace 8; tab key value 9;
4.event is global in IE and is a temporary object in Firefox, and parameters need to be passed
*/

jQuery.extend({
/*========= ================================================== ================
Function description: Get the value of the key
Calling 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: Determine whether it is an integer, restrict the edit box to only input numbers
Calling method:

Problems to be solved:
The tab key does not work in Firefox.
*/
isInt:function(e){
var keynum = this.getKeyNum(e);
if(keynum >= 48 && keynum <= 57 || keynum == 8 ){//Backspace under firefox needs to be judged 8
return true;
}
return false;
},
/*============= ================================================== ============
Function description: Determine whether it is a decimal. Limit the edit box to only numbers and one decimal point.
Calling method:

*/
isFloat:function(txt,e) {
var keynum = this.getKeyNum(e);
if(keynum == 46){//Input 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;
}
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn