更新时间:2023-12-05 12:20:10
最简单的方法是创建CSS规则的样式表.
The easiest way of doing this is by creating a CSS rule's stylesheet.
在该样式表中,您应该定义 2个类.
In that stylesheet, you should define 2 classes.
让我们假设1是您想要的CSS规则,另一个是默认/无规则.
Let's suppose 1 for your desired CSS rules and the other for the default/none rules.
我只是向您展示该操作的最简单版本,但具有另一个方面.
I am just showing you the simplest version of doing this thing but with another aspect.
$('#b1').on('click', function() {
$('.c1').removeClass('c1');
$(this).addClass('c2');
});
.c1 {
color: red;
}
.c2 {
color: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="b1">Change</button>
<p class="c1">This is a Test Line.</p>