阻止Firefox中jQuery键盘按下的默认事件
|
我有jQuery代码,它使可聚焦元素的数组组成并绑定.keydown左右箭头以通过它们进行制表。在Chrome,IE和Safari中,以“ 0”开头或以return false结尾(技术上我不想使用,因为我不需要使用“ 1”)结束了箭头的默认事件,但在Firefox中却没有。
如何防止Firefox中的默认操作?
这是可以正常工作的代码,但在Firefox中,除了我的回调外,还会触发默认事件。
$(function () {
var focusables = $(\":focusable\");
focusables.eq(0).focus();
focusables.eq(0).select();
focusables.each(function () {
$(this).keydown(function (e) {
if (e.which == \'37\') { // left-arrow
e.preventDefault();
var current = focusables.index(this),
next = focusables.eq(current - 1).length ? focusables.eq(current - 1) : focusables.eq(0);
next.focus();
next.select();
}
if (e.which == \'39\') { // right-arrow
e.preventDefault();
var current = focusables.index(this),
next = focusables.eq(current + 1).length ? focusables.eq(current + 1) : focusables.eq(0);
next.focus();
next.select();
}
});
});
});
没有找到相关结果
已邀请:
2 个回复
赐黄
演示位于http://jsfiddle.net/roberkules/3vA53/
靛新比比催