File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed
慕课网教程案例/jQuery入门教程/jQuery核心 Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 17
17
</ style >
18
18
< script src ="http://libs.baidu.com/jquery/1.9.1/jquery.js "> </ script >
19
19
</ head >
20
-
20
+
21
21
< body >
22
22
< h2 > each方法</ h2 >
23
23
< p > 慕课网,专注分享</ p >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+
4
+ < head >
5
+ < meta http-equiv ="Content-type " content ="text/html; charset=utf-8 " />
6
+ < title > </ title >
7
+ < style >
8
+ p {
9
+ color : red;
10
+ }
11
+ div {
12
+ width : 200px ;
13
+ height : 100px ;
14
+ background-color : yellow;
15
+ color : red;
16
+ }
17
+ </ style >
18
+ < script src ="http://libs.baidu.com/jquery/1.9.1/jquery.js "> </ script >
19
+ </ head >
20
+
21
+ < body >
22
+ < h2 > inArray方法</ h2 >
23
+ < p > 慕课网,专注分享</ p >
24
+ < div id ="aaron "> </ div >
25
+ 点击观察结果:
26
+ < select id ="animation ">
27
+ < option value ="1 "> inArray</ option >
28
+ < option value ="2 "> each对象</ option >
29
+ </ select >
30
+ < input id ="exec " type ="button " value ="执行动画 ">
31
+ < script type ="text/javascript ">
32
+ $ ( "#exec" ) . click ( function ( ) {
33
+ var v = $ ( "#animation" ) . val ( ) ;
34
+ var $aaron = $ ( "#aaron" ) ;
35
+ $aaron . empty ( ) ;
36
+ if ( v == "1" ) {
37
+
38
+ // 遍历数组元素
39
+ var exist = $ . inArray ( 'Aaron' , [ 'Aaron' , '慕课网' ] ) ;
40
+
41
+ alert ( exist )
42
+
43
+ } else if ( v == "2" ) {
44
+ // 遍历对象属性
45
+ $ . each ( {
46
+ name : "张三" ,
47
+ age : 18
48
+ } , function ( property , value ) {
49
+ $aaron . append ( "属性名=" + property + "; 属性值=" + value ) ;
50
+ } ) ;
51
+ }
52
+ } ) ;
53
+ </ script >
54
+ </ body >
55
+
56
+ </ html >
You can’t perform that action at this time.
0 commit comments