-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo82.html
48 lines (47 loc) · 904 Bytes
/
demo82.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jquery实现tab栏目切换</title>
<style>
span{
display: inline-block;
width: 50px;
text-align: center;
cursor: pointer;
}
.selected{
color: red;
}
p{
display: none;
}
.show{
display: block;
}
</style>
</head>
<body>
<div id="tab">
<span class="selected">1</span>
<span>2</span>
<span>3</span>
</div>
<div id="content">
<p class="show">a</p>
<p>b</p>
<p>c</p>
</div>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(function () {
$("#tab span").click(function () {
var i = $(this).index();// 下标第一种写法
// var i = $("#tab span").index(this);// 下标第二种写法
$(this).addClass("selected").siblings().removeClass("selected");
$("#content p").eq(i).show().siblings().hide();
});
});
</script>
</body>
</html>