1

jQuery / Underscore を使用して、次のリストを指定します。.msgli w 内にないすべての要素を見つけるにはどうすればよいですかdata-allow-html="true"

<ol>
    <li><div class="msg">message</div></li>
    <li data-allow-html="true"><div class="msg">message</div></li>
    <li><div class="msg">message</div></li>
    <li data-allow-html="true"><div class="msg">message</div></li>
    <li><div class="msg">message</div></li>
    <li data-allow-html="true"><div class="msg">message</div></li>
    <li><div class="msg">message</div></li>
    <li data-allow-html="true"><div class="msg">message</div></li>
</ol>

私は現在持っています:

$('#mydiv').find('.msg').each(function() {}

そして試しました:

$('#mydiv').find('li').not('data-allow-html="true"').find('.msg').each(function() {}

うまくいかないようです。アイデア?ありがとう

4

2 に答える 2

2

次を使用してすべての<li>withingを取得し、属性が含まれているかどう#mydivかを確認してからnot()、それぞれを見つけることができます.msg

$('#mydiv li').not('[data-allow-html="true"]').find('.msg').each(function() {
    // your code
});​
于 2012-10-25T00:35:22.593 に答える
1

あなたのコードでは、これは .. // Missing []not('data-allow-html="true"')
である はずですnot('[data-allow-html="true"]')

この方法で試すこともできます

 $('li').not('[data-allow-html]').find('.msg').each(function() {

       $(this).css('color', 'orange')
        // Your code here
 });

//また

$('li:not([data-allow-html])').find('.msg').each(function() {

});

フィドルをチェック

于 2012-10-25T00:36:31.267 に答える