原生js jquery
add()====addclasss()
remover()==removeclass()
<p id="app">hello world</p><button id="btn">移除</button><script>var app=document.getElementById("app");var btn =document.getElementById("btn")app.onclick =function(){this.classList.add("current");}btn.onclick =function(){app.classList.remove("current");}</script>
2toggle
.current{color: red;}
原生js jquery<!-- toggel()===toggelclass() --><!-- contains()====hasclass() --><p id="app">hello world</p><script>var app= document.getElementById("app");app.onclick=function(){// if(this.classList.contains("current")){// this.classList.remove("current");// }// else{// this.classList.add("current");// }this.classList.toggle("current")}</script>
