📜  使用函数用 JS 更改 CSS - 剥离所有 CSS 并重新添加由第二个参数传递的类 - 作为数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:08.885000             🧑  作者: Mango

代码示例1
function changeCSS(select, cssArray){
    //function that Removes ClassList
    //then adds back that that DOM element
    // this only works because elem is stored in Memory
    var myArray = [];
    
    var elem = document.getElementsByClassName(select);
    for(var i=0; i{
      console.log(myArray);
      myArray[index].removeAttribute('class');
      myArray[index].classList.add(select);
    });
    
    for(var ii=0; ii{
        myArray[ii].classList.add(item);
      });
    }  
}