Jquery Enter To Tab
时间:2010-11-10 来源:Nosnowwolf
代码 document.onkeydown = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
document.onkeyup = function(evt) {
var isie = (document.all) ? true : false;
var key;
var srcobj;
alert(isie);
if (isie) {
key = event.keyCode;
srcobj = event.srcElement;
}
else {
alert(evt);
key = evt.which;
srcobj = evt.target;
}
if (key == 13 && srcobj.type != 'button' && srcobj.type != 'submit' && srcobj.type != 'reset' && srcobj.type != 'textarea' && srcobj.type != '') {
if (isie) {
event.keyCode = 9;
}
else {
var el = getNextElement(evt.target);
if (el.type != 'hidden')
el.focus();
else
while (el.type == 'hidden')
el = getNextElement(el);
el.focus();
return false;
}
}
}
function getNextElement(field) {
var form = field.form;
for (var e = 0; e < form.elements.length; e++) {
if (field == form.elements[e])
break;
}
return form.elements[++e % form.elements.length];
}
function document.onkeydown() {
var e = event.srcElement;
if (event.keyCode == 13 && e.tagName == "INPUT" && e.type == "text")
event.keyCode = 9;
}
相关阅读 更多 +