-
Notifications
You must be signed in to change notification settings - Fork 1
/
test5.html
75 lines (68 loc) · 1.8 KB
/
test5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>模拟下拉选项卡</title>
<style>
.ul{
display: none;
}
</style>
</head>
<body>
<ul id="first">
<li class="li-ul">123
<ul class="ul">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</li>
<li>
<ul class="ul">
<li></li>
<li></li>
<li></li>
</ul>
</li>
<li>
<ul class="ul">
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>
<script>
window.onload = function(){
bindUl();
}
function bindUl(){
var oUl = document.getElementById('first');
var oLi = oUl.getElementsByTagName('li');
var oUl2 = document.getElementsByClassName('li-ul');
for(var i = 0; i < oUl2.length ;i++){
/*oUl2[i].attrChange("onclick",function(){
this.removeAttribute("class");
})*/
if(oUl2[i].addEventListener){
oUl2[i].addEventListener("click",function(){
//this.getElementsByClassName('ul')[0].className;
if(this.getElementsByClassName('ul').length>0){
this.getElementsByClassName('ul')[0].removeAttribute("class");
}
else{
this.getElementsByTagName('ul')[0].setAttribute("class","ul");
}
},false);
}else if(oUl2[i].attachEvent){
oUl2[i].attachEvent("onclick",function(){
var a = this.nextSibling||this.nextElementSibling;
a.removeAttribute("class");
});
}
}
}
</script>
</body>
</html>