div当您在文本框中键入时,我会弹出一个项目列表.
在模糊文本框时,我隐藏了项目列表.
但是,由于focusout事件首先触发,因此我在不再触发的项目上单击事件.
我想要的是隐藏模糊列表,除非点击列表中的项目.
有谁知道一种方式?
在提问时,它应该与本网站的标签部分相同.
使用jQuery 1.6或更高版本,您可以使用:焦点选择器在隐藏div之前查看您的div是否有任何具有焦点的子节点.
$("#textboxID").blur(function () {
if ($("#divID").has(":focus").length == 0) { //if you click on anything other than the results
$("#divID").hide(); //hide the results
}
});
Run Code Online (Sandbox Code Playgroud)
更新:原来只在IE中有效.这是一个更好的解决方案,虽然这个任务有点复杂. http://jsfiddle.net/cB2CN/
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
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7229 次 |
| 最近记录: |