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