-1

子要素の id を見て div 要素をフィルタリングしようとしていますが、機能していないようで、その理由を特定できません。

html:

<div class="section-link" id="section-tooltip">
    <div class="brand tp" style="display: none;"></div>
    contents
</div>

<div class="section-link" id="section-tooltip">
    <div class="brand garden" style="display: none;"></div>
    contents
</div>

js:

function brand(string){
    var brand = string;
    $('.section-link').hide();
    if ($(".section-link").children('.brand').hasClass(brand)) {
        $(this).parent().show();
    }
}

次に、Chrome ブラウザを介して次のコードを実行しています: javascript:brand("tp");

すべての div を非表示にしますが、内部に tp 要素があるものは表示しません

4

2 に答える 2

2

$("this") は間違っています。

$(this) //this is right

編集。もう1つ:そうではありません

.hasclass()

しかし

.hasClass()
于 2013-07-19T15:32:20.117 に答える