博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

分析CMMS系统笔记---使用js控制快捷键

Posted on 2011-08-11 14:22  bug yang  阅读(374)  评论(0编辑  收藏  举报

使用js控制快捷键

/**
* Events are handled for different browsers.
*/
CalemLogin._handleKeyEvents
=
function(event) {
event
= event || window.event; //Either passed in or directly from window
if (event == null) return true;

var target = event.target ? event.target: event.srcElement; //get the target of the event
if (!target) return true;

//Process key presses
var keyCode = event.keyCode || event.charCode;
if (keyCode == 13) { // Enter key 点击entry按钮时提交
if (target.id==CalemLogin.usernameEl) {//Move to password
document.getElementById(CalemLogin.passwordEl).focus();
}
else if ( (target.id==CalemLogin.passwordEl || target.id==CalemLogin.loginEl)
&& document.getElementById(CalemLogin.loginEl).disabled==false) {
CalemLogin._attemptLogin();
}
CalemLogin._cancelEvent(event);
return false;
}
else if (keyCode == 9) { // Tab
var handled=false;
var shiftKey = event.shiftKey;
if (shiftKey) {
if (target.id==CalemLogin.usernameEl) {
handled
=true;
if (document.getElementById(CalemLogin.loginEl).disabled) {
//Do no do anything - cannot move on to disabled button.
} else {
document.getElementById(CalemLogin.loginEl).focus();
}
}
else if (target.id==CalemLogin.loginEl) {
document.getElementById(CalemLogin.passwordEl).focus();
handled
=true;
}
}
else if (target.id==CalemLogin.loginEl) { //Do not tab into the browser window
document.getElementById(CalemLogin.usernameEl).focus();
handled
=true;
}
else if (target.id==CalemLogin.passwordEl
&& document.getElementById(CalemLogin.loginEl).disabled) {
//Cannot move to disabled
handled=true;
}
if (handled) {
CalemLogin._cancelEvent(event);
return false;
}
}
//Not handling here
return true;
}