用这个Jquery多个选择器

Tom*_*len 2 javascript jquery jquery-selectors

我已经搜索但无法找到如何做到这一点.我正在尝试使用comment-modbox内部this隐藏和显示元素:

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

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

    $(this, '.comment-modbox').mouseout(function () {
        $('.comment-modbox').hide();
    });
});
Run Code Online (Sandbox Code Playgroud)

此代码隐藏并显示所有内容,comment-modbox无论它们是否包含在内this.

谢谢你的帮助!

回答:

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

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

    $(this).mouseout(function () {
        $('.comment-modbox', this).hide();
    });
});
Run Code Online (Sandbox Code Playgroud)

and*_*lzo 6

试试这个(jQuery("选择器",上下文)...)

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

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

    $('.comment-modbox', this).mouseout(function () {
        $(this).hide();
    });
});
Run Code Online (Sandbox Code Playgroud)

第二选择:

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

    var wrapper = this; 

    $('.comment-modbox', wrapper)
        .mouseover(function () {
            $(this).show();
        })
        .mouseout(function () {
            $(this).hide();
        });
});
Run Code Online (Sandbox Code Playgroud)