File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 < title > </ title >
55 < script type ="text/javascript " src ="jquery-latest.js "> </ script >
66</ head >
7- < body onload ="kk33() ">
7+ < body onload ="">
88
99< table id ="t1 ">
1010 < tr class ="odd ">
1515 </ tr >
1616 < tr class ="even ">
1717 < td > </ td >
18- < td > </ td >
18+ < td > s </ td >
1919 < td > </ td >
2020 < td > </ td >
2121 </ tr >
4848
4949 </ tr >
5050</ table >
51+ < input type ="button " onclick ="hasText() ">
5152< script >
5253 function kk ( ) {
5354
6869 function kk32 ( ) {
6970 var result = '' ;
7071 $ ( "table" ) . each ( function ( ) {
71- result = result + $ ( "td" , $ ( ".odd" , this ) ) . length + "\n" + $ ( "tr.even" , this ) . length + "\n" ;
72+ result = result + $ ( "td" , $ ( ".odd" , this ) ) . length + "\n" + $ ( "tr.even" , this ) . length + "\n" ;
7273 } )
7374 alert ( result ) ;
7475 }
9293 }
9394
9495
95- function kk33 ( ) {
96+ function kk33 ( ) {
9697 var result = '' ;
9798 $ ( "table" ) . each ( function ( ) {
98- result = result + $ ( "tr.odd td" , this ) . length + "\n" + $ ( "tr.even td" , this ) . length + "\n" ;
99-
100-
99+ result = result + $ ( "tr.odd td" , this ) . length + "\n" + $ ( "tr.even td" , this ) . length + "\n" ;
101100 } )
102101 alert ( result ) ;
103102 }
104103
105104
106-
107-
105+ function hasText ( ) {
106+ var count = 0 ;
107+ //遍历tr
108+ $ ( "tr" , "#t1" ) . each ( function ( ) {
109+ //判定此tr下空td数量与总td数量是否相等
110+ if ( $ ( "td:empty" , this ) . length != $ ( "td" , this ) . length ) {
111+ count ++ ;
112+ }
113+ } )
114+ alert ( count ) ;
115+ }
108116
109117
110118</ script >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > </ title >
5+ < script type ="text/javascript " src ="jquery-latest.js "> </ script >
6+ < meta charset ="UTF-8 ">
7+ < style >
8+ tr {
9+ height : 20px ;
10+ }
11+
12+ td {
13+ width : 20px ;
14+ }
15+
16+ .oddtr {
17+ background-color : blue;
18+ }
19+
20+ .oddtd {
21+ background-color : red;
22+ }
23+ .oddtrtd {
24+ background-color : yellow;
25+ }
26+ </ style >
27+
28+ </ head >
29+ < body >
30+ < table id ="t1 " border ="1 ">
31+ < tr >
32+ < td > </ td >
33+ < td > </ td >
34+ < td > </ td >
35+ < td > </ td >
36+ </ tr >
37+ < tr >
38+ < td > </ td >
39+ < td > </ td >
40+ < td > </ td >
41+ < td > </ td >
42+ </ tr >
43+ < tr >
44+ < td > </ td >
45+ < td > </ td >
46+ < td > </ td >
47+ < td > </ td >
48+ </ tr >
49+ </ table >
50+
51+
52+ < table id ="t2 " border ="1 ">
53+ < tr >
54+ < td > </ td >
55+ < td > </ td >
56+ < td > </ td >
57+
58+ </ tr >
59+ < tr >
60+ < td > </ td >
61+ < td > </ td >
62+ < td > </ td >
63+
64+ </ tr >
65+ < tr >
66+ < td > </ td >
67+ < td > </ td >
68+ < td > </ td >
69+
70+ </ tr >
71+ </ table >
72+ < input type ="button " onclick ="addClass() ">
73+
74+
75+ < script >
76+
77+ function addClass ( ) {
78+ $ ( "table" ) . each ( function ( ) {
79+ $ ( "tr" , this ) . each ( function ( ind , ele ) {
80+ if ( ind % 2 == 0 ) {
81+ $ ( ele ) . addClass ( "oddtr" ) ;
82+ $ ( "td" , this ) . each ( function ( ind , ele ) {
83+ if ( ind % 2 == 0 ) {
84+ $ ( ele ) . addClass ( "oddtrtd" ) ;
85+ } else {
86+ $ ( ele ) . addClass ( "eventd" ) ;
87+ }
88+ } )
89+ } else {
90+ $ ( ele ) . addClass ( "eventr" ) ;
91+ $ ( "td" , this ) . each ( function ( ind , ele ) {
92+ if ( ind % 2 == 0 ) {
93+ $ ( ele ) . addClass ( "oddtd" ) ;
94+ } else {
95+ $ ( ele ) . addClass ( "eventd" ) ;
96+ }
97+ } )
98+ }
99+ } )
100+ } )
101+ alert ( $ ( "tr.oddtr" ) . length ) ;
102+ }
103+
104+ </ script >
105+ </ body >
106+ </ html >
Original file line number Diff line number Diff line change 99
1010 function countChecked ( ) {
1111
12- alert ( $ ( ":checked input[type='radio']" ) . length ) ;
12+ // alert($("input[type='radio']:checked ").attr("value") );
1313
1414
15- //
16- //
17- // if($(":checked"," input[type='radio']").value=="color1"){
18- // alert( $(":checked"," input[name='color1']").length);
19- //
20- // }else if($(":checked"," input[type='radio']").value=="color2"){
21- // alert( $(":checked"," input[name='color2']").length);
22- // }
15+
16+
17+ if ( $ ( "input[type='radio']:checked " ) . attr ( " value" ) == "color1" ) {
18+ alert ( $ ( "input[name='color1']:checked " ) . length ) ;
19+
20+ } else if ( $ ( "input[type='radio']:checked " ) . attr ( " value" ) == "color2" ) {
21+ alert ( $ ( "input[name='color2']:checked " ) . length ) ;
22+ }
2323
2424
2525
You can’t perform that action at this time.
0 commit comments