HTML
<style>
.active{
color:green;
}
</style>
<div id="customer-links-content" class="active">来回添加删除类名</div>
<script>
...
</script>
方法一:
var div1 = document.querySelector("#customer-links-content");
div1.addEventListener("click", function () {
div1.classList.toggle('active');
})
方法二:
var div1 = document.querySelector("#customer-links-content");
div1.addEventListener("click", function () {
if (div1.classList.contains("active")) {
div1.classList.remove("active");
} else {
div1.classList.add("active");
}
})