作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个消息框,上面有两个按钮。基本上它是一个 jQuery 插件,带有叠加效果的弹出窗口。但是,当出现消息框并且用户按下选项卡按钮时,消息对话框不会聚焦。 那么如果我的消息框出现,然后焦点自动转到我的消息框,我该怎么办?当焦点丢失并且用户再次按选项卡按钮时,它会再次返回到我的消息对话框 如果我用鼠标单击消息框,然后按选项卡按钮,则焦点将转到按钮,然后消失。这是图像 。这是制作盒子的代码。
var containerDiv = $("<div></div>", {
id: config.containerDivID
});
// append all the div to main Div(container)
containerDiv.append(messageDiv, buttonDiv);
centerPopup(config, containerDiv);
loadPopup(config);
function centerPopup(config, container){
var backgroundPopup = $("<div></div>", {
id: "backgroundPopup"
}); //end of imageDiv
$("body").append(backgroundPopup);
$("body").append(container);
$("#backgroundPopup").css({
"height": windowHeight
});
} //end of centerPopup()
function loadPopup(config){
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#" + config.containerDivID).fadeIn("slow");
popupStatus = 1;
} //end of if
} //end of function loadPopup()
谢谢
最佳答案
tabindex
是 div 的东西。将其设置为零,原生 HTML5 将插入正确的 tabindex
。请记住,全部小写:
<div tabindex=0> Stuff Here </div>
这将允许您使用键盘聚焦 div。
<div tabindex=0, autofocus=true> Stuff Here </div>
// select it with
document.querySelector("[autofocus]").focus();
// or with smelly jQuery
$([autofocus]).focus();
如果您使用 jQuery,则可以通过以下方式轻松找到焦点 div
:
var $focused = $(':focus');
然后做一些事情,比如.click()
:
$focused.click()
这将点击那个东西。
关于jquery - 如何让键盘选项卡聚焦于div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10227038/
我是一名优秀的程序员,十分优秀!