代码示例:(标识:jsck_element_classlist_remove_2)
<!DOCTYPE html>
<html>
<style>
.myStyle {
background-color: coral;
padding: 16px;
}
.anotherClass {
text-align: center;
font-size: 25px;
}
.thirdClass {
text-transform: uppercase;
}
</style>
<body>
<h1>DOMToken 对象</h1>
<h2>remove() 方法</h2>
<button onclick="myFunction()">删除</button>
<p>请单击“删除”,从 myDIV 中删除多个类。</p>
<div id="myDIV" class="myStyle anotherClass thirdClass">
<p>I am myDIV.</p>
</div>
<p>Internet Explorer 9 及更早版本不支持 classList 属性。</p>
<script>
function myFunction() {
document.getElementById("myDIV").classList.remove("myStyle", "anotherClass", "thirdClass");
}
</script>
</body>
</html>