事件捕捉问题


<style type="text/css">
ul,li{ list-style-type:none;margin:0;padding:0;width:200px;}

ulwrap ul{display:none;}

</style>
</head>

<body>

  • 第一级
    • 第二级
      • 第三级
        • 第四级
        • 第四级
      • 第三级
    • 第二级
  • 第一级2
    • 第二级2
    • 第二级2

<

script type="text/javascript">

var ulWrap = document.getElementById('ulwrap');
var liWrap = ulWrap.getElementsByTagName('li');
var ulWrapx = liWrap[0].getElementsByTagName('ul');

for(var i = 0;i<liWrap.length;i++){
liWrap[i].index = i;
for(var j=0;j<liWrap[i].childNodes.length;j++){
if(liWrap[i].childNodes[j].nodeName.toUpperCase() == "UL"){
liWrap[i].childNodes[j].style.paddingLeft = "50px";
}
}
liWrap[i].onclick = function(){


 if(this.childNodes[j] && (this.childNodes[j].nodeName.toUpperCase() == "UL")){
        //if(!this.childNodes[j].flage){
            this.childNodes[j].style.display = "block";
            //this.childNodes[j].flage = true;
        //}else{
            this.childNodes[j].style.display = "none";
            //this.childNodes[j].flage = false; 
        //}
    }   
}

}

/*function digui(target){


 for(var j=0;j<target.childNodes.length;j++){
    if(target.childNodes[j].nodeName.toUpperCase() == "UL"){
        target.childNodes[j].style.paddingLeft = "50px";    
    }
}

}*/
</script>
没问题了解决了

事件

飘落食指大人 9 years, 5 months ago

Your Answer