25
检查元素是否包含JavaScript中的类?
使用普通的JavaScript(不是jQuery),是否可以检查元素是否包含类? 目前,我正在这样做: var test = document.getElementById("test"); var testClass = test.className; switch (testClass) { case "class1": test.innerHTML = "I have class1"; break; case "class2": test.innerHTML = "I have class2"; break; case "class3": test.innerHTML = "I have class3"; break; case "class4": test.innerHTML = "I have class4"; break; default: test.innerHTML = ""; } …
585
javascript
html
css
dom