Case 1: interlace, swipe, click to change color (check cancel effect) (AddClass (), Removeclass (), Toggleclass ())
Html:Css:table{font-size:12px;border-collapse:collapse;border:1px solid #A9C9E2;} td,th{padding:5px;border:1px solid #A9C9E2;} Tr{cursor:pointer;} . Tab01{background: #EEFAFF;} Tr.even{background: #F0FBEB;} Tr.highlight,td.highlight,th.highlight{background: #FFFFDD;} //Highlight class for JS dynamic addtr.selected{background: #C2ECA7;} (Note: Because Tr.even set the color, highlight must indicate TR, TD, TH, otherwise tr.even not effect) JS: $ ('. Tab01 tr:even '). addclass (' even '); //Slide$ ('. Tab01 tr:not (: First) '). Hover (function(){ $( This). AddClass (' Highlight '); }, function(){ $( This). Removeclass (' Highlight '); }); //Click to change color$ ('. Tab01 tr:not (: First) '). Click (function(){ $( This). Toggleclass (' selected '); }); //Slide of the table head$ ('. TAB01st '). Hover (function(){ varColindex = $ ( This). index (); $('. Tab01 td:nth-child (' + (Colindex + 1) + '),. Tab01 Th:nth-child (' + (Colindex + 1) + ') '). AddClass (' highlight ');//Select column to add highlight class},function(){ $('. TAB01 tr '). Children (). Removeclass (' Highlight '); });
2. Add a column of buttons to the above table , select the row button to tick and line color (hasclass,removeclass,removeattr,)
Js://Add style selected by default$ ('. TAB02 input[type= ' checkbox ']:checked '). Parents (' tr '). AddClass (' selected '));$(". Tab02 Tr:not (: First)"). Click (function(){ if($( This). Hasclass ("Selected")){ $( This). Removeclass ("Selected"); $( This). Find (' input[type= "checkbox"] '). Removeattr ("Checked"); } Else{ $( This). AddClass ("Selected"); $( This). Find (' input[type=checkbox] '). attr ("Checked", "checked"); }});
jquery Operation Table Instance