鼠标悬停事件后 addClass() 不起作用
addClass() not work after mouseover event
大家好,当我添加 class 使用 jquery
添加 class 无效
$('.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),它们不是同一个目标。
大家好,当我添加 class 使用 jquery
添加 class 无效
$('.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),它们不是同一个目标。