File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed
慕课网教程案例/jQuery入门教程/jQuery核心 Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 9
9
10
10
font-size : 30px ;
11
11
font-weight : 900 ;
12
- }
12
+ }
13
13
14
14
div {
15
15
width : 200px ;
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
+ a {
9
+ font-size : 30px ;
10
+ font-weight : 900 ;
11
+ }
12
+ </ style >
13
+ < script src ="http://libs.baidu.com/jquery/1.9.1/jquery.js "> </ script >
14
+ </ head >
15
+
16
+ < body >
17
+ < h2 > index方法</ h2 >
18
+ < ul >
19
+ < a > </ a >
20
+ < a > </ a >
21
+ < li id ="test1 "> 1</ li >
22
+ < li id ="test2 "> 2</ li >
23
+ < li id ="test3 "> 3</ li >
24
+ </ ul >
25
+ < ul >
26
+ < li id ="test4 "> 4</ li >
27
+ < li id ="test5 "> 5</ li >
28
+ < li id ="test6 "> 6</ li >
29
+ </ ul >
30
+ < select id ="animation ">
31
+ < option value ="1 "> index无参数</ option >
32
+ < option value ="2 "> index传递dom</ option >
33
+ < option value ="3 "> index传递jQuery对象</ option >
34
+ </ select >
35
+ < input id ="exec " type ="button " value ="点击执行 ">
36
+ < br />
37
+ < br /> 索引结果:
38
+ < span > </ span >
39
+ < script type ="text/javascript ">
40
+ $ ( "#exec" ) . click ( function ( ) {
41
+ var v = $ ( "#animation" ) . val ( ) ;
42
+
43
+ var $span = $ ( "span" ) ;
44
+ $span . empty ( ) ;
45
+
46
+ if ( v == "1" ) {
47
+ //找到第一个li的同辈节点中的索引位置
48
+ $span . text ( $ ( "li" ) . index ( ) )
49
+ } else if ( v == "2" ) {
50
+
51
+ //通过传递dom查找
52
+ $span . text ( $ ( "li" ) . index ( document . getElementById ( "test5" ) ) )
53
+
54
+ } else if ( v == "3" ) {
55
+ //通过传递jQuery对象查找
56
+ $span . text ( $ ( "li" ) . index ( $ ( "#test6" ) ) )
57
+
58
+ }
59
+ } ) ;
60
+ </ script >
61
+ </ body >
62
+
63
+ </ html >
You can’t perform that action at this time.
0 commit comments