代码示例:(标识:jsck_element_classlist_contains_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>contains() 和 remove() 方法</h2>

<p>如果 “myDIV” 有 “myStyle” 类,请单击“删除”来移除 “anotherClass”。</p>

<button onclick="myFunction()">删除</button>


<div id="myDIV" class="myStyle anotherClass thirdClass">
<p>I am myDIV.</p>
</div>

<script>
function myFunction() {
  const element = document.getElementById("myDIV");
  if (element.classList.contains("myStyle")) {
    element.classList.remove("anotherClass");
  }
}
</script>

</body>
</html>
运行结果: