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('');

 });

別のオプションは、リストをクリアする前に遅延を設定することです。これは、ユーザーがリストから 1 つの項目のみを選択する必要がある場合に機能します。

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

それが役に立てば幸い!

于 2013-07-11T22:50:33.940 に答える