zoukankan      html  css  js  c++  java
  • addClass和removeClass函数

      function addClass1(element,value){
            if(!element.className){
                element.className = value;
            }else{
                newClassName = element.className;
                newClassName += " ";
                newClassName += value;
                element.className =newClassName;
            };
        };
        function addClass2(ele,className){
            ele.className += " " + className;
        };
        function addClass3(node,className){
            return node.className += " " + className;
        };
    

      

       function removeClass2(ele,className){
            var tmpClassName = ele.className;
            ele.className = null;
            ele.className = tmpClassName.split(new RegExp(" " + className + "|" + className + " " + "|" + "^" + className + "$","ig")).join("");
        };
        function removeClass3(node,className){
            eles = node.className.split(/s+/);//先将已有的class放进数组
            for(var i = 0; i < eles.length; i++){
                if(eles[i] == className){
                    eles.splice(i,1);//再遍历删除指定的class
                };
            };
            node.className = eles.join("");//最后将新的数组用空格隔开重新添加回className
            return node;
        };
    

      

  • 相关阅读:
    Luogu P5853 [USACO19DEC]Tree Depth P
    Luogu P6009 [USACO20JAN]Non-Decreasing Subsequences P
    HDU6309 Absolute
    Luogu P4734 [BalticOI 2015]Hacker
    Gym102431F Ferry
    Gym102431G Game on the Tree
    AGC018F Two Trees
    Gym102268D Dates
    AGC023F 01 on Tree
    CF700E Cool Slogans
  • 原文地址:https://www.cnblogs.com/archrjoe/p/4118191.html
Copyright © 2011-2022 走看看