类操作,removeClass&addClass

// 添加类
function addClass(node,className){
                var reg=new RegExp("\\b"+className+"\\b");
                if(!reg.test(node.className)){
                    node.className +=(" "+className);
                }
}
 
// 移除类
function removeClass(node,className){
                if(node.className){
                    var reg=new RegExp("\\b"+className+"\\b");
                    var classes = node.className;
                    node.className=classes.replace(reg,"");
                    if(/^\s*$/g.test(node.className)){
                        node.removeAttribute("class");
                    }
                }else{
                    node.removeAttribute("class");
                }
}
 
上一篇:jquery优化02


下一篇:HTML5新特性:元素的classList属性与应用