当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 扩展jQuery 键盘事件的几个基本方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 扩展jQuery 键盘事件的几个基本方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 629 ::
收藏到网摘: n/a

扩展jQuery 键盘事件的几个基本方法(练习jQuery插件扩展) 文件名:jquery.hy.key.js
复制代码 代码如下:

/* ================================================================================
Desc: 扩展对键盘事件的方法
Called by:
Auth: 大气象
Date: 2009-10-30
================================================================================
Change History
================================================================================
Date: Author: Description:
-------- -------- -------------------
================================================================================
Copyright (C) 1992-2009 Hongye Corporation
================================================================================
预备知识
1.数字0键值48..数字9键值57
2.a键值97..z键值122;A键值65..Z键值90
3.+键值43;-键值45;.键值46;退格8;tab键值9;
4.event在ie中是全局的,在firefox是临时对象,需要传递参数
*/
jQuery.extend({
/*===========================================================================
功能描述:取得按键的值
调用方法:
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;
},
/*===========================================================================
功能描述:判断是否是整数,限制编辑框只能输入数字
调用方法:
<input type="text" onkeypress="return jQuery.isInt(event);" />
待解决问题:
firefox下tab键不起作用。
*/
isInt:function(e){
var keynum = this.getKeyNum(e);
if(keynum >= 48 && keynum <= 57 || keynum == 8){//firefox下退格需判断8
return true;
}
return false;
},
/*===========================================================================
功能描述:判断是否是小数,限制编辑框只能输入数字,只能输入一个小数点。
调用方法:
<input type="text" onkeypress="return jQuery.isFloat(this,event);" />
*/
isFloat:function(txt,e){
var keynum = this.getKeyNum(e);
if(keynum == 46){//输入小数点
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;
}
});