gpt4 book ai didi

jQuery .has (":focus") 在 FF/Chrome/Safari 中

转载 作者:行者123 更新时间:2023-12-01 03:49:21 25 4
gpt4 key购买 nike

我有一个文本框,当您在其下方键入结果时,该文本框会进行过滤。我有 jQuery 来检测焦点何时离开文本框,以便它可以隐藏结果 div。但如果单击结果,我不想隐藏结果,以便我可以使用该单击重定向到该项目的不同页面。

我正在使用 .has(":focus") 来检查我的结果 div 或其任何子级是否具有焦点。我的问题是,据我所知,这只适用于 IE。有谁知道为什么吗?

$("#TextBox").blur(function () {
if ($("#ResultsDIV").has(":focus").length == 0) { //if you click on anything other than the results
$("#ResultsDIV").hide(); //hide the results
}
});

更新:感谢 Climbage,我已经成功了...

var resultsSelected = false;
$("#ResultsDIV").hover(
function () { resultsSelected = true; },
function () { resultsSelected = false; }
);
$("#TextBox").blur(function () {
if (!resultsSelected) { //if you click on anything other than the results
$("#ResultsDIV").hide(); //hide the results
}
});

工作示例: http://jsfiddle.net/cB2CN/

最佳答案

问题是 DOM 上的所有 not 元素实际上都接受焦点,并且由浏览器决定哪些元素接受焦点。请参阅Which HTML elements can receive focus?

也许您的 #ResultsDIV 上有一个 hover 事件,该事件设置一个全局变量来确定当您单击该元素时该元素是否具有焦点。

关于jQuery .has (":focus") 在 FF/Chrome/Safari 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10391823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com