[英]execute jquery command unless user clicks on a div
我有一個用戶搜索欄,它創建一個包含相關用戶的div,當您集中精力時它會消失。 但是,如果我單擊用戶列表div,則我不想集中精力。 這有可能實現嗎?
application.js:
$(function() {
$("#user_header_search_form input").focusout(function() {
$('#header_user_list').html('');
});
});
$('#header_user_list')。html(''); 如果用戶單擊“ #header_user_list”,我不想運行此鏈接
一種替代方法可能是:
$(document).click(function(event){
var clicked = $(event.target);
//if the clicked element is not son of the input or the list, clear the list.
if(clicked.closest("#user_header_search_form input,#header_user_list").size() == 0)
$('#header_user_list').html('');
});
另一種選擇是在清除列表之前設置延遲。 如果用戶必須從列表中僅選擇一項,這將起作用:
$("#user_header_search_form input").focusout(function() {
setTimeout(function(){
$('#header_user_list').html('');
},50);
});
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.