用这个Jquery多个选择器

我已经搜索但无法找到如何做到这一点。 我正在尝试使用comment-modboxthis hide中创建元素并显示:

 $('.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(“选择器”,上下文)… )

 $('.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(); }); });