码迷,mamicode.com
首页 > 其他好文 > 详细

追加addclass和removeclass

时间:2016-04-04 14:34:57      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

//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;
            }

追加addclass和removeclass

标签:

原文地址:http://www.cnblogs.com/xiaodonger/p/5351873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!