标签:
function addClass(id,new_class){
var i,n=0;
new_class=new_class.split(",");
for(i=0;i<new_class.length;i++){
if((" "+document.getElementById(id).className+" ").indexOf(" "+new_class[i]+" ")==-1){
document.getElementById(id).className+=" "+new_class[i];
n++;
}
}
return n;
}
现代浏览器有classList属性:
var addClass = function(_element, _classes) {
var classList, item, _i, _len;
classList = _element.classList;
for (_i = 0, _len = _classes.length; _i < _len; _i++) {
item = _classes[_i]; classList.add(item);
}
return _element;
};
原生addClass 方法 添加类函数
标签:
原文地址:http://www.cnblogs.com/chuangweili/p/5159611.html