js dom 添加类

       var  sheng =  document.getElementById("sheng");
        var  falge =0;
        sheng.onclick = function()
        {
            if(this.parentNode.classList.contains('linkage-selected')){   //检查类
                this.parentNode.classList.remove("linkage-selected");  //添加类
                 //this.nextElementSibling.style.display="none";
            }else{
                this.parentNode.classList.add("linkage-selected");
                //this.nextElementSibling.style.display=" block";  //设置样式
            }
  
        }

 

        //dd下的单击事件
        var sheng_dds =  sheng.parentNode.getElementsByTagName("dl")[0].children;  //获得子节点

 

posted @ 2019-09-03 11:18  enych  阅读(674)  评论(0编辑  收藏  举报