0

クラスが「検索可能」の div で検索を実行したいのですが、どのように選択すればよいかわかりません。以前のコードのようなものを試しましたが、うまくいきませんでした。

                $('#SEARCH').change(function () {
                //if (e.which == 13) {
                    var txt = $('#SEARCH').val();
                    $('.divin').each(function(){
                       if($(this + ' > .searchable').text().toUpperCase().indexOf(txt.toUpperCase()) == -1){
                           $(this).hide();
                       }
                    });
                //}
            });

($(this + ' > .searchable')は正しくありません

HTML:

<li id="listItem_156" class="divin">
<div style="width:30px;">
    <a href="#?w=800" rel="popup_name" id="156" class="poplight">
        <img height="16" style="cursor:move;" width="16" src="img/arrow.png" border="0"  />
    </a>
</div>
<div style="width:220px;" class="searchable">
    <a href="action=MemberDetails&item=156" class="body">Mike Frank </a> 
</div>
<div style="width:110px;">
    0 
</div>

4

4 に答える 4

2

使用するjQuery.find

if($(this).find(' >.searchable').text().toUpperCase().indexOf(txt.toUpperCase()) == -1){
      $(this).hide();
}
于 2013-04-13T19:00:01.860 に答える
0

jsfiddleで

    $('#SEARCH').change(function () {
        var txt = $('#SEARCH').val();
        $('.divin .searchable').show().filter(function () {
              return $(this).text().toUpperCase().indexOf(txt.toUpperCase()) === -1
        }).hide();

    });
于 2013-04-13T19:17:41.643 に答える
0

なぜ直接これをしないのですか

 $('.divin .searchable').each(function(){

したがって

 $('#SEARCH').change(function () {
                //if (e.which == 13) {
                    var txt = $('#SEARCH').val();
                    $('.divin .searchable').each(function(){
                       if($(this).text().toUpperCase().indexOf(txt.toUpperCase()) == -1){
                           $(this).parent().hide();
                       }
                    });
                //}
            });
于 2013-04-13T19:05:46.347 に答える