<!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>add() 方法</h2>
<button onclick="myFunction()">添加</button>
<p>请单击“添加”,将多个类添加到 myDIV。</p>
<div id="myDIV">
<p>I am myDIV.</p>
</div>
<p>Internet Explorer 9 及更早版本不支持 classList 属性。</p>
<script>
function myFunction() {
document.getElementById("myDIV").classList.add("myStyle", "anotherClass", "thirdClass");
}
</script>
</body>
</html>