JsjQuery 学科作业部分代码展示-选项卡版本

荆雪

此页面用于存放jQ学科作业()

-为避免影响阅读,可以点击代码块内右上角的小箭头折叠单个代码块-
-幽默目录不用管😅😅😅😋ヾ(≧▽≦*)o-你别管诶嘿w-
展示网页可能因内嵌于静态构建而出现显示异常w

代码部分:

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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>

<div class="box">DOM</div>
<script src="./js/jquery-3.7.1.min.js"></script>
<script>
//js获取div.box
var box = document.querySelector('.box');
console.log('box ==> ', box);
//获取节点:$(css选择器)
//jq获取div.box
var $box = $('.box');
console.log('$box ==> ', $box);
//在$box取出原生DOM节点
// var box1 = $box[0];
var box1 = $box.get(0);
console.log('box1 ==> ', box1);
//将js获取的DOM节点转换为jq对象
var $box2 = $(box);
console.log('$box2 ==> ', $box2);
</script>
</body>

</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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>

<h2 class="title">
jQuery
</h2>

<div class="box">
<h1>CSS</h1>
<ul>
<li>A</li>
<li>B</li>
</ul>
</div>

<input id="username" type="text" placeholder="输入用户名">
<button id="btn">节点内容</button>
<script src="./js/jquery-3.7.1.min.js"></script>
<script>
//为button#btn绑定点击事件
$('#btn').click(function () {
console.log('点击了');
//获取h2.title的普通文本内容
var text = $('.title').text();
console.log('text ==> ', text);
//修改h2.title的普通文本内容
$('.title').text('<a>jQuery DOM 库</a>');
//获取div.box的标签内容
var html = $('.box').html();
console.log('html ==> ', html);
//修改div.box的标签内容
$('.box').html('<a>jQuery DOM 库</a>');
//获取input#username的内容
var val = $('#username').val();
console.log('val ==> ', val);
//修改input#username的内容
$('#username').val('Mark');
})
</script>
</body>

</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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 300px;
height: 300px;
background-color: #ddd;
}

.active {
background-color: #e4393c;
}

.br {
border-radius: 20px;
}
</style>
</head>

<body>

<div class="box br"></div>
<button id="btn">样式操作</button>

<script src="./js/jquery-3.7.1.min.js"></script>
<script>
//类名操作: 操作一组固定样式
//内联样式操作: 修改某一个属性, 比如修改宽度修改高度
$('#btn').click(function () {
//添加类名
// $('.box').addClass('active');
//移除类名
// $('.box').removeClass('br');
//判断类名是否存在
// var isHas = $('.box').hasClass('active');
// console.log('isHas ==> ', isHas);
//切换类名
//如果存在active, 则移除active; 如果不存在active, 则添加active
$('.box').toggleClass('active');
//内联样式
//css(css属性名称, css属性值)
// $('.box').css('width', 600);
// $('.box').css('height', '500px');
//css({css属性名称1: css属性值1, css属性名称2: css属性值2})
$('.box').css({
width: 600,
height: '500px',
backgroundColor: '#bcfa1a'
})
})
</script>
</body>

</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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul {
padding: 0;
list-style: none;
}

li {
padding: 15px 0;
}

.box {
width: 400px;
height: 400px;
background-color: #ddd;
display: none;
}
</style>
</head>

<body>
<ul>
<li>
<span>赵云</span>
<button class="edit">编辑</button>
</li>
<li>
<span>张飞</span>
<button class="edit">编辑</button>
</li>
<li>
<span>关羽</span>
<button class="edit">编辑</button>
</li>
<li>
<span>刘备</span>
<button class="edit">编辑</button>
</li>
</ul>

<!-- 编辑时,显示的弹窗 -->
<div class="box">
<div>
<input id="username" type="text" placeholder="输入用户名" />
</div>
<div>
<button id="save">保存</button>
<button id="cancel">取消</button>
</div>
</div>

<script src="./js/jquery-3.7.1.min.js"></script>
<script>

//记录编辑内容的节点
var $prev = null;

//给所有button.edit绑定点击事件
$('.edit').click(function () {
console.log('this ==> ', this);

//获取当前点击的节点的上一个节点span
$prev = $(this).prev();
console.log('$prev ==> ', $prev);
//获取$prev的文本内容
var text = $prev.text();
console.log('text ==> ', text);
// 往input#username写入text
$('#username').val(text);
//显示编辑弹窗
$('.box').show();
})

//保存
$('#save').click(function () {
//获取编辑的内容
var username = $('#username').val();
console.log('username ==> ', username);
//修改用户内容
$prev.text(username);
//清空input#username的内容
$('#username').val('');
//音频编辑弹窗
$('.box').hide();
})

//取消
$('#cancel').click(function () {
//清空input#username的内容
$('#username').val('');
//音频编辑弹窗
$('.box').hide();
})
</script>
</body>

</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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.tab {
display: flex;
background-color: #ddd;
width: 800px;
margin: 0 auto;
}

.tab-item {
width: 160px;
height: 40px;
line-height: 40px;
font-size: 14px;
color: #444;
text-align: center;
cursor: pointer;
}

.tab-item.active {
background-color: #e4393c;
color: #fff;
}
</style>
</head>

<body>

<div class="tab">
<div class="tab-item active">商品介绍</div>
<div class="tab-item">规格与包装</div>
<div class="tab-item">售后保障</div>
<div class="tab-item">商品评价(50000)</div>
<div class="tab-item">手机社区</div>
</div>

<script src="./js/jquery-3.7.1.min.js"></script>
<script>

$('.tab-item').click(function () {
//写法一
//给当前点击的节点添加active类名
// $(this).addClass('active');
//给当前点击的节点的含有active类名的兄弟节点移除active类名
// $(this).siblings('.active').removeClass('active');

//写法二
//链式调用
$(this).addClass('active').siblings('.active').removeClass('active');

//获取其他兄弟节点
//siblings(): 获取所有兄弟节点
//siblings('.active'): 获取含有.active类名的兄弟节点
// var siblings = $(this).siblings('.active');
// console.log('siblings ==> ', siblings);
})
</script>
</body>

</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
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>荆雪の标题w-</title>
<link rel="stylesheet" type="text/css" href="./style/default.css" />
</head>

<body>
<div class="king">
<ul>
<li class="current">
<div class="small red1"></div>
<div class="big red2"></div>
</li>
<li>
<div class="small orange1"></div>
<div class="big orange2"></div>
</li>
<li>
<div class="small yellow1"></div>
<div class="big yellow2"></div>
</li>
<li>
<div class="small green1"></div>
<div class="big green2"></div>
</li>
<li>
<div class="small blue1"></div>
<div class="big blue2"></div>
</li>
<li>
<div class="small pink1"></div>
<div class="big pink2"></div>
</li>
<li>
<div class="small purple1"></div>
<div class="big purple2"></div>
</li>
</ul>
</div>

<script src="./js/jquery-3.7.1.min.js"></script>
<script>
// 鼠标指针经过某个li
$(".king li").mouseenter(function () {
// 当前小li 宽度变为 224px,同时里面的小图片淡出,大图片淡入
$(this).stop().animate({
width: 224
}).find(".small").stop().fadeOut().siblings(".big").stop().fadeIn();
// 其余兄弟li宽度变为69px,小图片淡入,大图片淡出
$(this).siblings("li").stop().animate({
width: 69
}).find(".small").stop().fadeIn().siblings(".big").stop().fadeOut();
});
</script>

</body>

</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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* 清除元素的margin和padding */
* {
margin: 0;
padding: 0;
}

/* 设置最外层盒子的样式 */
.king {
width: 709px;
margin: 100px auto;
/*background: url(images/bg.png) no-repeat;*/
background-color: #1E4D75;
overflow: hidden;
padding: 10px;
border-radius: 10px;
}

/* 取消列表的默认样式 */
.king ul {
list-style: none;
}

/* 设置列表的样式 */
.king li {
position: relative;
float: left;
width: 69px;
height: 69px;
margin-right: 10px;
}

/* 设置初始状态 */
.king li.current {
width: 224px;
}

.king li.current .big {
display: block;
}

.king li.current .small {
display: none;
}

/* 设置大方块样式 */
.big {
width: 224px;
height: 69px;
display: none;
border-radius: 5px;
}

/* 设置小方块样式 */
.small {
position: absolute;
top: 0;
left: 0;
width: 69px;
height: 69px;
border-radius: 5px;
}

/* 设置大小方块的背景色*/
.red1 {
background: #FF3333;
}

.red2 {
background: #CC0000;
}

.orange1 {
background: #FFBB66;
}

.orange2 {
background: #FF8800;
}

.yellow1 {
background: #FFFFBB;
}

.yellow2 {
background: #FFFF77;
}

.green1 {
background: #99FF99;
}

.green2 {
background: #66FF66;
}

.blue1 {
background: #00BBFF;
}

.blue2 {
background: #0066FF;
}

.pink1 {
background: #FF88C2;
}

.pink2 {
background: #FF44AA;
}

.purple1 {
background: #E93EFF;
}

.purple2 {
background: #CC00FF;
}

展示网页:单击此处

嘻嘻,故意写多一个空着,诶嘿