javascript - Jquery 多选择器与此

标签 javascript jquery jquery-selectors

我已经搜索过,但找不到如何执行此操作。我正在尝试使用 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();
        });
});

关于javascript - Jquery 多选择器与此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5708901/

相关文章:

javascript - 通过部分指定第一个参数值来设置 select 的值

javascript - 将输入表单设置为只读?

javascript - 尽管给出了高度, Owl Carousel 仍不显示图像

javascript - setInterval JavaScript 不工作

jquery - 使用 jquery 选择文档根目录

javascript - React 路由器 v4 浏览器历史记录不适用于代码拆分

javascript - Connect-assetmanager 文件与 req.url 不匹配

javascript - D3.js force directed graph,通过使边缘相互排斥来减少边缘交叉

jquery - 过滤除此之外的内容

javascript - jQuery DOM 更改未出现在 View 源中