function KeyDownProcess() {
//-----------------------------------------------------------
//網頁親和性輸入控制元件
//元件功能:可以讓網頁資料的輸入更親切,功能如下:
//1.按下Enter鍵自動找到下一個可輸入輸入元件
//2.按下Enter鍵自動找尋submit按鍵,如果找到則模擬Click的功能
//版本:1.1(2009.03.27)
//作者:科碩資訊有限公司
//引用本元件,請保留作者和版本資訊
//聯絡mail:cursor@cursorinfo.com.tw
//------------------------------------------------------------
var kv = 0;
var rv = false;
var isTextarea = false;
var currentId = null; //目前元件
if (document.all && typeof (document.all) == "object") {
kv = event.keyCode;
isTextarea = (event.srcElement.tagName == "TEXTAREA");
currentId = event.srcElement.id;
}
else {
kv = evt.keyCode;
isTextarea = (evt.target == "TEXTAREA");
currentId = evt.id;
}
switch (kv) {
case 13:
if (currentId.length == 0)
return false;
if (isTextarea == true) {
rv = isTextarea;
}
else {
var cts = document.all && typeof (document.all) == "object" ? document.all : document.getElementsByTagName('input');
var cid = "";
var queryBu = null;
var beginNext = false; //開始比對是否為輸入元件
var nextInput = null; //下一個輸入元件
var specialSubmitId = "logonBU"; //指定特例的submit id
var exceptionSubmitId = "waitting"; //指定例外的submit Id
for (ii = 0; ii < cts.length; ii++) {
if (cts[ii].id == currentId) {
beginNext = true;
continue;
}
if (beginNext == true && (cts[ii].id.indexOf(specialSubmitId) > -1 || (cts[ii].type == "submit" && cts[ii].id.indexOf(exceptionSubmitId) == -1))) {
queryBu = cts[ii]; //找到submit元件
break;
}
else if (beginNext == true && (cts[ii].type == "text" || cts[ii].type == "textarea" || cts[ii].type == "password") && cts[ii].readOnly == false && cts[ii].style.display != "none") {
nextInput = cts[ii]; //找到下一個文字輸入元件
break;
}
}
if (null != queryBu) {
setTimeout("doClickId('" + queryBu.id + "');", 100);
rv = false;
}
else if (null != nextInput) {
try {
nextInput.focus();
} catch (Error) { return true; }
rv = false;
}
}
break;
default:
rv = true;
break;
}
return rv;
}
//實做模擬Click的功能
function doClickId(source) {
var o=document.getElementById(source);
if (document.all && typeof (document.all) == "object") //IE
o.click();
else {
var e = document.createEvent('mouseEvent');
e.initEvent('click', false, false);
o.dispatchEvent(e);
}
}
沒有留言:
張貼留言