File tree Expand file tree Collapse file tree 3 files changed +20
-35
lines changed
慕课网教程案例/jQuery入门教程/jQuery的节点操作 Expand file tree Collapse file tree 3 files changed +20
-35
lines changed Original file line number Diff line number Diff line change 4
4
< head >
5
5
< meta http-equiv ="Content-type " content ="text/html; charset=utf-8 " />
6
6
< 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 >
8
8
< style >
9
- .left ,
10
- .right {
11
- width : 250px ;
12
- height : 120px ;
13
- }
14
-
15
9
.left div ,
16
10
.right div {
17
11
width : 100px ;
18
- height : 120px ;
19
12
padding : 5px ;
20
13
margin : 5px ;
21
14
float : left;
26
19
.right div {
27
20
background : yellow;
28
21
}
22
+
23
+ p {
24
+ background-color : red;
25
+ }
26
+
27
+ a {
28
+ background-color : blue;
29
+ }
29
30
</ style >
30
31
</ head >
31
32
32
-
33
33
< body >
34
34
< h2 > DOM包裹wrap()方法</ h2 >
35
35
< 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 >
38
38
</ div >
39
39
< div class ="right ">
40
40
< p > p元素</ p >
Original file line number Diff line number Diff line change 4
4
< head >
5
5
< meta http-equiv ="Content-type " content ="text/html; charset=utf-8 " />
6
6
< 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 >
8
8
< style >
9
9
.left ,
10
10
.right {
29
29
< h2 > 通过clone克隆元素</ h2 >
30
30
< div class ="left ">
31
31
< div class ="aaron1 "> 点击,clone浅拷贝</ div >
32
- < div class ="aaron2 "> 点击,clone深拷贝</ div >
32
+ < div class ="aaron2 "> 点击,clone深拷贝,可以继续出发事件 </ div >
33
33
</ div >
34
34
< script type ="text/javascript ">
35
35
//只克隆节点
@@ -43,7 +43,8 @@ <h2>通过clone克隆元素</h2>
43
43
//克隆节点
44
44
//克隆事件
45
45
$ ( ".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' ) )
47
48
} )
48
49
</ script >
49
50
</ body >
Original file line number Diff line number Diff line change 6
6
< title > </ title >
7
7
< script src ="http://libs.baidu.com/jquery/1.9.1/jquery.js "> </ script >
8
8
< 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
+
26
10
.right div {
27
11
background : yellow;
28
12
}
32
16
< body >
33
17
< h2 > replaceWith()和replaceAll()</ h2 >
34
18
< 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 >
37
21
</ div >
38
22
< div class ="right ">
39
23
< div >
@@ -50,7 +34,7 @@ <h2>replaceWith()和replaceAll()</h2>
50
34
< script type ="text/javascript ">
51
35
//只克隆节点
52
36
//不克隆事件
53
- $ ( ".aaron1 " ) . on ( 'click' , function ( ) {
37
+ $ ( ".bt1 " ) . on ( 'click' , function ( ) {
54
38
//找到内容为第二段的p元素
55
39
//通过replaceWith删除并替换这个节点
56
40
$ ( ".right > div:first p:eq(1)" ) . replaceWith ( '<a style="color:red">replaceWith替换第二段的内容</a>' )
@@ -59,7 +43,7 @@ <h2>replaceWith()和replaceAll()</h2>
59
43
< script type ="text/javascript ">
60
44
//找到内容为第六段的p元素
61
45
//通过replaceAll删除并替换这个节点
62
- $ ( ".aaron2 " ) . on ( 'click' , function ( ) {
46
+ $ ( ".bt2 " ) . on ( 'click' , function ( ) {
63
47
$ ( '<a style="color:red">replaceAll替换第六段的内容</a>' ) . replaceAll ( '.right > div:last p:last' ) ;
64
48
} )
65
49
</ script >
You can’t perform that action at this time.
0 commit comments