追加addclass和removeclass

//addclass
            Base.prototype.addclass=function(classname){
                for(var i=0;i<this.elements.length;i++)
                {
                    //去重
                    if(!this.elements[i].className.match(new RegExp('(\\s|^)'+classname+'($|\\s)')))
                    {
                        this.elements[i].className+=" "+classname
                    }
 
                }
                return this;
            }
            //removeclass
            Base.prototype.removeclass=function(classname){
                for(var i=0;i<this.elements.length;i++)
                {
                    //去重
                    if(this.elements[i].className.match(new RegExp('(\\s|^)'+classname+'($|\\s)')))
                    {
                        this.elements[i].className=this.elements[i].className.replace(new RegExp('(\\s|^)'+classname+'($|\\s)'))," ")
                    }
 
                }
                return this;
            }
posted @ 2016-04-04 13:44  小董儿博客  阅读(278)  评论(0编辑  收藏  举报