dom中classList对象常用方法

添加新的类名,如已经存在,取消添加
classList.add( newClassName );
var str = document.getElementById('str');
str.classList.add('newClassname')
确定元素中是否包含指定的类名,返回值为true 、false;
classList.contains( oldClassName );
var str = document.getElementById('str');
str.classList.contains('newClassname') //return true/false
移除已经存在的类名;classList.remove( oldClassName );
var str = document.getElementById('str');
str.classList.add('newClassname') //移除类名newClassname
如果classList中存在给定的值,删除它,否则,添加它;(适用于开关切换)classList.toggle( className );
var str = document.getElementById('str');
str.classList.add('select')//切换class
str.classList.add('select',i<10)//第二参数是条件
类名替换classList.replace( oldClassName,newClassName );
var str = document.getElementById('str');
str.classList.add('select','newSelect')