代码示例:(标识:jsck_element_classlist_length)
<!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>length 属性</h2>

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

<p>myDIV 中的类名数量为:</p>

<p id="demo"></p>

<script>
let numb = document.getElementById("myDIV").classList.length;
document.getElementById("demo").innerHTML = numb;
</script>

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