2
我在您鍵入它下面的結果具有過濾器一個文本框。我有jQuery檢測焦點何時離開文本框,以便它可以隱藏結果div。但我並不想隱藏的結果,如果結果是點擊,這樣我可以使用點擊重定向到該項目不同的頁面。jQuery的。先後(「:聚焦」)在FF /鉻/ Safari瀏覽器
我正在使用.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
}
});
UPDATE:感謝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/
天才!懸停的想法工作... – Paul