原生
node.classList.remove(someClass);
node.classList.add(newClass);
node.classList.contains(someClass);
模拟
function addClass(node, newClass) {
var arr = node.className.split(/\s+/);
arr.push(newClass);
return arr.join(' ');
}
function removeClass(node, someClass) {
var arr = node.className.split(/\s+/);
arr = arr.filter(item => {
item !== someClass;
})
return arr.join(' ');
}
function containClass(node, someClass) {
var arr = node.className.split(/\s+/);
return arr.forEach(item => {
if (item === someClass) {
return true;
}
})
}