【发布时间】:2014-05-27 12:40:50
【问题描述】:
在 stackoverflow 中某人的帮助下,我使下面的这个脚本在 chrome 中运行良好。
(function($) {
$.fn.enterAsTab = function(options) {
var settings = $.extend({
'allowSubmit': false
}, options);
$(this).find('input, select, textarea, button').on("keypress", {localSettings: settings}, function(event) {
if (settings.allowSubmit) {
var type = $(this).attr("type");
if (type == "submit") {
return true;
}
}
if (event.keyCode == 13) {
var inputs = $(this).parents("form").eq(0).find(":input:visible:not(:disabled):not([readonly])");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
idx = -1;
} else {
inputs[idx + 1].focus(); // handles submit buttons
}
try {
inputs[idx + 1].select();
}
catch (err) {
// handle objects not offering select
}
return false;
}
});
return this;
};
})(jQuery);
但此代码在 Firefox 中无法完全运行。不工作的部分是选择。当我处于下拉菜单(选择)中时,我无法使用 enter 移动到下一个字段。
提前谢谢你。
【问题讨论】:
标签: javascript jquery google-chrome firefox