簡體   English   中英

jQuery與此的多個選擇器

[英]Jquery multiple selectors with this

我已經搜索過,但找不到如何執行此操作。 我正在嘗試在this隱藏和顯示中使用帶有comment-modbox的元素:

$('.comment-wrapper').each(function (index) {

    $(this, '.comment-modbox').mouseover(function () {
        $('.comment-modbox').show();
    });

    $(this, '.comment-modbox').mouseout(function () {
        $('.comment-modbox').hide();
    });
});

這段代碼只是隱藏並顯示所有comment-modbox無論它們是否包含在this

謝謝你的幫助!

回答:

$('.comment-wrapper').each(function (index) {

    $(this).mouseover(function () {
        $('.comment-modbox', this).show();
    });

    $(this).mouseout(function () {
        $('.comment-modbox', this).hide();
    });
});

試試這個( jQuery(“ selector”,context)...

$('.comment-wrapper').each(function (index) {

    $('.comment-modbox', this).mouseover(function () {
        $(this).show();
    });

    $('.comment-modbox', this).mouseout(function () {
        $(this).hide();
    });
});

第二選擇:

$('.comment-wrapper').each(function (index) {

    var wrapper = this; 

    $('.comment-modbox', wrapper)
        .mouseover(function () {
            $(this).show();
        })
        .mouseout(function () {
            $(this).hide();
        });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM