我是靠谱客的博主 稳重溪流,这篇文章主要介绍css中的classlist的意思是什么,现在分享给大家,希望可以做个参考。

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

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

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

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

语法

复制代码
1
element.classList
登录后复制

SSGQ2E{TZ[}$E4$[BWE[`NQ.png

方法

H~J{]U9S]K)N20V5$JINZ1Z.png

实例:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>document</title> <style> .mystyle { width: 500px; height: 50px; padding: 15px; border: 1px solid black; } .anotherClass { background-color: coral; color: white; } .thirdClass { text-transform: uppercase; text-align: center; font-size: 25px; } </style> </head> <body> <p>点击按钮为 DIV 元素添加多个类。</p> <button onclick="myFunction()">点我</button> <p><strong>注意:</strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 classList 属性。</p> <div id="myDIV"> 我是一个 DIV 元素。 </div> <script> function myFunction() { document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass"); } </script> </body> </html>
登录后复制

效果:

GIF.gif

推荐学习:css视频教程

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

最后

以上就是稳重溪流最近收集整理的关于css中的classlist的意思是什么的全部内容,更多相关css中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部