jquery Operation Table Instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.