事件捕捉问题
<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>
没问题了解决了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论