我正在制作一个基于网页的应用程序,该应用程序只有键盘(操纵杆)导航。我使用 tabindex,但我还需要禁用地址栏、搜索栏或页面之外的任何其他内容的焦点。
此应用程序只能在一台特定设备上运行,因此可以(实际上需要)禁用某些功能。
可能吗?
最佳答案
这是一个很酷的问题。
编辑:添加了向后的[shift]+[tab]。
尝试这个脚本,(working Fiddle here):
var firstInputObj;
var lastInputObj;
$("input").each(function(){
if($(this).attr("tabIndex")=="1"){
firstInputObj=$(this);
}
lastInputObj=$(this);
});
$(firstInputObj).focus();
// tab (forward)
$(lastInputObj).on("keydown",function(e){
if(!e.shiftKey && e.which==9){
e.preventDefault();
$(firstInputObj).focus();
}
});
// Shift tab (backward)
$(firstInputObj).on("keydown",function(e){
if(e.shiftKey && e.keyCode == 9) {
e.preventDefault();
$(lastInputObj).focus();
}
});
关于javascript - 禁用页面外的焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38043074/