Skip to content

Commit 7655755

Browse files
committed
DOM包裹wrap()方法
1 parent 40b4975 commit 7655755

File tree

3 files changed

+20
-35
lines changed

3 files changed

+20
-35
lines changed

慕课网教程案例/jQuery入门教程/jQuery的节点操作/DOM包裹wrap()方法.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
<head>
55
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
66
<title></title>
7-
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
7+
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
88
<style>
9-
.left,
10-
.right {
11-
width: 250px;
12-
height: 120px;
13-
}
14-
159
.left div,
1610
.right div {
1711
width: 100px;
18-
height: 120px;
1912
padding: 5px;
2013
margin: 5px;
2114
float: left;
@@ -26,15 +19,22 @@
2619
.right div {
2720
background: yellow;
2821
}
22+
23+
p {
24+
background-color: red;
25+
}
26+
27+
a {
28+
background-color: blue;
29+
}
2930
</style>
3031
</head>
3132

32-
3333
<body>
3434
<h2>DOM包裹wrap()方法</h2>
3535
<div class="left">
36-
<div class="aaron1">点击,通过wrap方法给p元素增加父容器div</div>
37-
<div class="aaron2">点击,通过wrap的回调方法给a元素增加父容器div</div>
36+
<button class="aaron1">点击,通过wrap方法给p元素增加父容器div</button>
37+
<button class="aaron2">点击,通过wrap的回调方法给a元素增加父容器div</div>
3838
</div>
3939
<div class="right">
4040
<p>p元素</p>

慕课网教程案例/jQuery入门教程/jQuery的节点操作/DOM拷贝clone().html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
66
<title></title>
7-
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
7+
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
88
<style>
99
.left,
1010
.right {
@@ -29,7 +29,7 @@
2929
<h2>通过clone克隆元素</h2>
3030
<div class="left">
3131
<div class="aaron1">点击,clone浅拷贝</div>
32-
<div class="aaron2">点击,clone深拷贝</div>
32+
<div class="aaron2">点击,clone深拷贝,可以继续出发事件</div>
3333
</div>
3434
<script type="text/javascript">
3535
//只克隆节点
@@ -43,7 +43,8 @@ <h2>通过clone克隆元素</h2>
4343
//克隆节点
4444
//克隆事件
4545
$(".aaron2").on('click', function() {
46-
$(".left").append($(this).clone(true).css('color','blue'))
46+
console.log(1)
47+
$(".left").append( $(this).clone(true).css('color','blue') )
4748
})
4849
</script>
4950
</body>

慕课网教程案例/jQuery入门教程/jQuery的节点操作/DOM替换replaceWith()和replaceAll().html

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,7 @@
66
<title></title>
77
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
88
<style>
9-
.left,
10-
.right {
11-
width: 300px;
12-
height: 120px;
13-
}
14-
15-
.left div,
16-
.right div {
17-
width: 100px;
18-
height: 120px;
19-
padding: 5px;
20-
margin: 5px;
21-
float: left;
22-
border: 1px solid #ccc;
23-
background: #bbffaa;
24-
}
25-
9+
2610
.right div {
2711
background: yellow;
2812
}
@@ -32,8 +16,8 @@
3216
<body>
3317
<h2>replaceWith()和replaceAll()</h2>
3418
<div class="left">
35-
<div class="aaron1">点击,通过replaceWith替换内容</div>
36-
<div class="aaron2">点击,通过rreplaceAll替换内容</div>
19+
<button class="bt1">点击,通过replaceWith替换内容</button>
20+
<button class="bt2">点击,通过rreplaceAll替换内容</button>
3721
</div>
3822
<div class="right">
3923
<div>
@@ -50,7 +34,7 @@ <h2>replaceWith()和replaceAll()</h2>
5034
<script type="text/javascript">
5135
//只克隆节点
5236
//不克隆事件
53-
$(".aaron1").on('click', function() {
37+
$(".bt1").on('click', function() {
5438
//找到内容为第二段的p元素
5539
//通过replaceWith删除并替换这个节点
5640
$(".right > div:first p:eq(1)").replaceWith('<a style="color:red">replaceWith替换第二段的内容</a>')
@@ -59,7 +43,7 @@ <h2>replaceWith()和replaceAll()</h2>
5943
<script type="text/javascript">
6044
//找到内容为第六段的p元素
6145
//通过replaceAll删除并替换这个节点
62-
$(".aaron2").on('click', function() {
46+
$(".bt2").on('click', function() {
6347
$('<a style="color:red">replaceAll替换第六段的内容</a>').replaceAll('.right > div:last p:last');
6448
})
6549
</script>

0 commit comments

Comments
 (0)