怎么用JS控制多个DIV的显示和隐藏问题
2个回答
展开全部
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="bb">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<input type="button" id="ss" value="js"/>
<input type="button" id="sss" value="jq"/>
</body>
<!--js-->
<script>
var $divList = document.getElementsByTagName('div'),
$btn = document.getElementById('ss'),
nowTag = 'none',
otherTag = 'block';
$btn.onclick = function() {
var i = 0,
len = $divList.length;
for(; i < len; i++) {
var $div = $divList[i];
if($div.className === 'aa') {
$div.style.display = nowTag;
}
}
changeTag();
}
function changeTag() {
var temp = nowTag;
nowTag = otherTag;
otherTag = temp;
}
</script>
<!--js end-->
<!--jq start-->
<script src="jq.js"></script>
<script>
$('#sss').on('click', function() {
$('.aa').toggle();
})
</script>
<!--jq end-->
</html>
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<div class="bb">aaa</div>
<div class="aa">aaa</div>
<div class="aa">aaa</div>
<input type="button" id="ss" value="js"/>
<input type="button" id="sss" value="jq"/>
</body>
<!--js-->
<script>
var $divList = document.getElementsByTagName('div'),
$btn = document.getElementById('ss'),
nowTag = 'none',
otherTag = 'block';
$btn.onclick = function() {
var i = 0,
len = $divList.length;
for(; i < len; i++) {
var $div = $divList[i];
if($div.className === 'aa') {
$div.style.display = nowTag;
}
}
changeTag();
}
function changeTag() {
var temp = nowTag;
nowTag = otherTag;
otherTag = temp;
}
</script>
<!--js end-->
<!--jq start-->
<script src="jq.js"></script>
<script>
$('#sss').on('click', function() {
$('.aa').toggle();
})
</script>
<!--jq end-->
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-09-16
展开全部
html代码:
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
JQ代码:
$(".div1").show();
$(".div1").siblings("div").hide();
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
JQ代码:
$(".div1").show();
$(".div1").siblings("div").hide();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询