大家好,当我使用 jquery
添加类时,添加的类不起作用
$('.t_wrapper').mouseover(function () {
$(this).addClass('t_active');
});
$('.t_wrapper').mouseout(function () {
$('.t_wrapper').removeClass('t_active');
});
//'.t_active'
无法识别父标签,抱歉我的英语:(
var tag = $('.t_active .tables li:nth-child(' + n + ')');
最佳答案
选项 1:
$('.t_wrapper').mouseenter(function () {
$(this).addClass('t_active');
});
$('.t_wrapper').mouseleave(function () {
$(this).removeClass('t_active');
});
选项2
$('.t_wrapper').mouseover(function () {
$('.t_wrapper').addClass('t_active');
});
$('.t_wrapper').mouseout(function () {
$('.t_wrapper').removeClass('t_active');
});
每次鼠标进入或离开子元素时,都会触发 mouseover,但不会触发 mouseenter。 因此,不要在 mouseover 或 mouseout 中使用 $(this),它们不是同一目标。
关于jquery - 鼠标悬停事件后 addClass() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27786644/