在网页上,让回车键(enter)模拟Tab键的效果
比百度各种搜索出来的方法都要好用
$('body').on('keydown', 'input, select', function(e) {
return enter2tab(this,e);
});
function enter2tab(obj,e){
var self = $(obj)
, form = self.parents('form:eq(0)')
, focusable
, next
;
if (e.keyCode == 13) {
focusable = form.find('input,select,button').filter(':visible');
next = focusable.eq(focusable.index(obj)+1);
if (next.length) {
next.focus();
} else {
form.submit();
}
return false;
}
}