封装键盘事件

//封装键盘事件

//作者:张沈鹏 >>http://www.cppblog.com/zuroc/

//版本:1.0_06-12-30

/*

用法演示:

var key= new KeyCode(event);

if(key.enter||key.esc)...

*/

//代码

function KeyCode(event){

if(!event)event=window.event;

keyCode = event.keyCode;

this.del=this.enter=this.esc=this.stepY=this.char=false;

switch(keyCode) {

//for space

//for backspace (8) and delete (46)

case 8:case 46:this.del=true;return;

case 13:this.enter=true;return;

case 27:this.esc=true;return;

case 32:this.char=true;return;

case 38:this.stepY=-1;return;

case 40:this.stepY=1;return; }

if (!( (keyCode < 46) || (keyCode >= 112 && keyCode <= 123) ))

{this.char=true;}

}

posted on 2006-12-30 00:34 张沈鹏 阅读(653) 评论(0)  编辑 收藏 引用 所属分类: 网页技术

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理