如何点击使用jQuery添加和删除类?我需要其他类别不受影响。使用jQuery添加和删除类
所以,当你点击.other-class.one它变成.other-class.two。如果你点击.other-class.two它会变成.other-class.one。
这就是我迄今为止的第二次JS加载工作。
<p class="other-class one">Trigger</p>
.one {
background: red;
}
.two {
background: blue;
}
.other-class {
text-decoration: underline;
}
$('.one').click(function(){
$(this).removeClass('one');
$(this).addClass('two');
});
$('.two').click(function(){
$(this).removeClass('two');
$(this).addClass('one');
});
为什么这个问题有这么多downvotes? – musefan 2014-12-02 11:04:53
我想说这个问题唯一不好的地方在于,OP没有明确提及JS的第二次加载不起作用。究竟发生了什么,不应该发生? – musefan 2014-12-02 11:11:09