0

我有一个用户搜索栏,它创建一个包含相关用户的 div,当你专注时它会消失。但是,如果我单击用户列表 div,我不想集中注意力。这有可能实现吗?

应用程序.js:

$(function() {
   $("#user_header_search_form input").focusout(function() {
      $('#header_user_list').html('');
   });
});

$('#header_user_list').html(''); 如果用户单击“#header_user_list”,我不想运行此链接

4

1 回答 1

0

另一种方法可能是:

 $(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);
 });

希望能帮助到你!

于 2013-07-11T22:50:33.940 回答