在这个单击函数中,作者为什么要删除类并再次添加类?
$('#alt').on('click', function() {
$('button').removeClass('active');
$(this).addClass('active');
$('.light').attr('class', 'light');
setTimeout(function() {
$('#light-1, #light-3, #light-5').attr('class', 'light strobe blue');
$('#light-2, #light-4, #light-6').attr('class', 'light strobe red delay');
}, 50);
});发布于 2019-04-29 04:01:31
可能作者希望重置活动按钮,而只希望单击为活动按钮。
$('button').removeClass('active');
$(this).addClass('active');附注:假设$(this)也是一个按钮。
您也可以使用jquery not编写它
$("button").not($(this)).removeClass('active');
https://stackoverflow.com/questions/55893865
复制相似问题