jQuery练习_Tab选项卡

  1. jQuery练习_Tab选项卡

jQuery练习_Tab选项卡

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TAB选项卡</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 440px;
height: 298px;
border: 1px solid #000;
margin: 50px auto;
}
.nav>li{
list-style: none;
width: 110px;
height: 50px;
background: orange;
text-align: center;
line-height: 50px;
float: left;
}
.nav>.current{
background: #ccc;
}
.content>li{
list-style: none;
display: none;
}
.content>.show{
display: block;
}
</style>
<script src="js/jquery-1.12.4.js"></script>
<script>
$(function () {
/*
// 1.监听选项卡的移入事件
$(".nav>li").mouseenter(function () {
// 1.1修改被移入选项卡的背景颜色
$(this).addClass("current");
// 1.2获取当前移入选项卡的索引
var index = $(this).index();
// 1.3根据索引找到对应的图片
var $li = $(".content>li").eq(index);
// 1.4显示找到的图片
$li.addClass("show");
});
// 1.监听选项卡的移出事件
$(".nav>li").mouseleave(function () {
// 1.1还原选项卡的背景颜色
$(this).removeClass("current");
// 1.2获取当前移出选项卡的索引
var index = $(this).index();
// 1.3根据索引找到对应的图片
var $li = $(".content>li").eq(index);
// 1.4隐藏对应的图片
$li.removeClass("show");
});
*/
// 1.监听选项卡的移入事件
$(".nav>li").mouseenter(function () {
// 1.1修改被移入选项卡的背景颜色
$(this).addClass("current");
// 1.2还原其它兄弟选项卡的背景颜色
$(this).siblings().removeClass("current");
// 1.3获取当前移出选项卡的索引
var index = $(this).index();
// 1.4根据索引找到对应的图片
var $li = $(".content>li").eq(index);
// 1.5隐藏非当前的其它图片
$li.siblings().removeClass("show");
// 1.6显示对应的图片
$li.addClass("show");
});
});
</script>
</head>
<body>
<div class="box">
<ul class="nav">
<li class="current">H5+C3</li>
<li>jQuery</li>
<li>C语言</li>
<li>Go语言</li>
</ul>
<ul class="content">
<li class="show"><img src="images/11.jpg" alt=""></li>
<li><img src="images/12.jpg" alt=""></li>
<li><img src="images/13.jpg" alt=""></li>
<li><img src="images/14.jpg" alt=""></li>
</ul>
</div>
</body>
</html>

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2113132982@qq.com

文章标题:jQuery练习_Tab选项卡

文章字数:548

本文作者:南邮石磊

发布时间:2020-07-22, 18:26:09

最后更新:2020-08-06, 00:32:31

原始链接:https://southpost.github.io/2020/07/22/jQuery%E7%BB%83%E4%B9%A0_Tab%E9%80%89%E9%A1%B9%E5%8D%A1/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏