ตัวอย่าง
Title | |
Data 1 | |
Data 2 | |
Data 3 | |
Data 4 | |
Data 5 | |
Data 6 | |
Data 7 | |
Data 8 | |
Data 9 | |
Data 10 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <style type= "text/css" > html,body{ margin : 0 ; padding : 0 ; font-family : Tahoma , Geneva, sans-serif ; font-size : 12px ; } /* css สำหรับแถวคี่ */ .RowOdd{ background-color : #EAEAEA ; } /* css สำหรับแถวคู่ */ .RowEven{ background-color : #FBFBFB ; } </style> |
HTML Code ตัวอย่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | < table class = "myTable" width = "500" border = "0" align = "center" cellpadding = "0" cellspacing = "0" > < tr > < td width = "49" align = "center" bgcolor = "#CCCCCC" >< input name = "checkAll" type = "checkbox" id = "checkAll" value = "1" /></ td > < td width = "451" bgcolor = "#CCCCCC" >Title</ td > </ tr > < tr class = "RowOdd" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "1" /> </ td > < td >Data 1</ td > </ tr > < tr class = "RowEven" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "2" /> </ td > < td >Data 2</ td > </ tr > < tr class = "RowOdd" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "3" /> </ td > < td >Data 3</ td > </ tr > < tr class = "RowEven" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "4" /> </ td > < td >Data 4</ td > </ tr > < tr class = "RowOdd" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "5" /> </ td > < td >Data 5</ td > </ tr > < tr class = "RowEven" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "6" /> </ td > < td >Data 6</ td > </ tr > < tr class = "RowOdd" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "7" /> </ td > < td >Data 7</ td > </ tr > < tr class = "RowEven" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "8" /> </ td > < td >Data 8</ td > </ tr > < tr class = "RowOdd" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "9" /> </ td > < td >Data 9</ td > </ tr > < tr class = "RowEven" > < td align = "center" > < input class = "myChkBox" name = "Item[]" type = "checkbox" id = "Item[]" value = "10" /> </ td > < td >Data 10</ td > </ tr > </ table > |
Javascript Code ตัวอย่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <script type= "text/javascript" src= "js/jquery-1.4.1.min.js" ></script> <script type= "text/javascript" > $( function (){ var HilightCSS={ "background-color" : "#FFC" } var NoHilightCSS={ "background-color" : "" } $( "#checkAll" ).click( function (){ var parentTR=$( ".RowOdd,.RowEven" ); var statusCheckBox=($( this ).attr( "checked" )== "checked" )? true : false ; $( this ).parents( ".myTable" ).find( ".myChkBox" ) .attr( "checked" ,statusCheckBox); if ($( this ).attr( "checked" )== "checked" ){ parentTR.css(HilightCSS); } else { parentTR.css(NoHilightCSS); } }); $( "input.myChkBox" ).click( function (){ var parentTR=$( this ).parents( ".RowOdd,.RowEven" ); if ($( this ).attr( "checked" )== "checked" ){ parentTR.css(HilightCSS); } else { parentTR.css(NoHilightCSS); } }); }); </script> |