好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

css中的classlist的意思是什么

classList属性返回元素的类名,作为DOMTokenList对象,该属性用于在元素中添加,移除及切换CSS类。classList属性是只读的,但你可以使用add()和remove()方法修改它。

本教程操作环境:windows7系统、CSS3 && HT ML 5版、Dell G3 电 脑。

classList 属性返回元素的类名,作为 DOMTokenList 对象。

该属性用于在元素中添加,移除及切换 CSS 类。

classList 属性是只读的,但你可以使用 add() 和 remove() 方法修改它。

语法

element.classList

方法

实例:

<!DOCTY PE  html>
<html>
<head>
< ;m eta charset="utf-8">
<t IT le>document</title>
<style>
.mystyle {
    width: 500px;
    h ei ght: 50px;
    padding: 15px;
    border: 1px solid black;
}
.anotherClass {
    background-color: coral;
    color: white;
}
.thirdClass {
    text -t ransform: uppercase;
    text-align:  center ;
    font- Size:  25px;
}
</style>
</head>
<body>

<p>点击按钮为 DIV 元素添加多个类。</p>
<button onclick="myFunction()">点我</button>
<p>< strong >注意:</strong>  internet  E xp lorer 9 及更早 IE 版本浏览器不支持 classList 属性。</p>
<div id="myDIV">
我是一个 DIV 元素。
</div>
<script>
function myFunction() {
    document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");
}
</script>

</body>
</html>

效果:

推荐学习:css视频教程

以上就是css中的classlist的 意思 是什么 的详细内容,更多请关注其它相关 文章 !

总结

以上是 为你收集整理的 css中的classlist的意思是什么 全部内容,希望文章能够帮你解决 css中的classlist的意思是什么 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于css中的classlist的意思是什么的详细内容...

  阅读:25次