成都网站建设设计

将想法与焦点和您一起共享

classList用于添加和删除CSS类的API

classList API提供了原生的方式来添加,删除,切换,或检查CSS类存在的元素。它比解析容易得多 element.className

1
2
3
4
6
7
8
9
10
element.classList.add( "someclass" ) //adds a class to element
element.classList.add( "class1" , "class2" , etc) //adds multiple CSS classes. Not supported in IE11 or FF26 or less.
element.classList.remove( "someclass" ) //removes a class from element
element.classList.remove( "class1" , "class2" , etc) //removes multiple CSS classes. Not supported in IE11 or FF26 or less.
element.classList.toggle( "someclass" ) //toggles a class. If already exists removes and returns false. Otherwise adds class and returns true
element.classList.toggle(“someclass”,expression) //根据表达式的结果添加或删除“someclass”。IE11或FF26或更低版本不支持。
"vertical-align: inherit;" > "vertical-align: inherit;" >
element.classList.contains(“someclass”) //检查元素中是否存在类

当前文章:classList用于添加和删除CSS类的API
网页网址:http://chengdu.cdxwcx.cn/article/pccpip.html