// 覆盖原来的样式 document.getElementById("test").setAttribute("class","test1"); var dom=document.getElementsByClassName("test")[0].setAttribute("class","test1"); // 追加样式不覆盖原来的样式 document.getElementById("test").classList.add("test1"); document.getElementById("test").classList.add("test1","test2","test3"); var dom=document.getElementsByClassName("test")[0].classList.add("test1"); var dom=document.getElementsByClassName("test")[0].classList.add("test1","test2","test3");