另一种使用纯 JavaScript 将类添加到元素的方法
添加类:
document.getElementById("div1").classList.add("classToBeAdded");
移除类:
document.getElementById("div1").classList.remove("classToBeRemoved");
注意:但在 IE 中不受支持
【讨论】:
-
注:“(I) guess (in) IE 8 and up.”
-
@在一个语句中添加和删除另一个的任何方式?