zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JS实现Enter键跳转及控件获得焦点

JS 实现 获得 控件 跳转 焦点 Enter
2023-06-13 09:15:04 时间
复制代码代码如下:

//回车跳转
jQuery(document).ready(function(){
//$(":input:text:first").focus();
jQuery(":input:enabled").addClass("enterIndex");
//getonlyinputtagswithclassdata-entry
textboxes=jQuery(".enterIndex");
//nowwechecktoseewhichbrowserisbeingused
if(jQuery.browser.mozilla){
jQuery(textboxes).bind("keypress",CheckForEnter);
}else{
jQuery(textboxes).bind("keydown",CheckForEnter);
}
});

functionSetControlEnterEvent(){
//$(":input:text:first").focus();
$(":input:enabled").addClass("enterIndex");
//getonlyinputtagswithclassdata-entry
textboxes=$(".enterIndex");
//nowwechecktoseewhichbrowserisbeingused
if($.browser.mozilla){
$(textboxes).bind("keypress",CheckForEnter);
}else{
$(textboxes).bind("keydown",CheckForEnter);
}
}

functionCheckForEnter(event){
if(event.keyCode==13&&$(this).attr("type")!="button"&&$(this).attr("type")!="submit"&&$(this).attr("type")!="textarea"&&$(this).attr("type")!="reset"){
vari=$(".enterIndex").index($(this));
varn=$(".enterIndex").length;
if(i<n-1){
if($(this).attr("type")!="radio"){
NextDOM($(".enterIndex"),i);
}
else{
varlast_radio=$(".enterIndex").index($(".enterIndex[type=radio][name="+$(this).attr("name")+"]:last"));
NextDOM($(".enterIndex"),last_radio);
}
}
returnfalse;
}
}
functionNextDOM(myjQueryObjects,counter){
if(myjQueryObjects.eq(counter+1)[0].disabled){
NextDOM(myjQueryObjects,counter+1);
}
else{
myjQueryObjects.eq(counter+1).trigger("focus");
}
}