jquery table interlaced color plug-in

Source: Internet
Author: User

Plug-in code
;(function($) {$.fn.extend ({"Alterbgcolor":function(options) {Options=$.extend ({"Odd": "Odd",//the class of even rows"Even": "Even",//Odd Line Class"Selected": "Selected"//The row class is clicked},options);//the passed-in class parameter replaces the default class settingconsole.info (Options) $ ("Tbody tr:odd"). addclass (options.odd);//even line set class$ ("Tbody Tr:even"). addclass (Options.even);//Odd Line Set class$ ("tbody tr"). Click (function(){//Click events for Table Rows //The current click line adds the selected style, the other lines remove the selected style, end () refers to the object and the $ (this), and the line's radio is selected$( This). addclass (options.selected). Siblings (). Removeclass (options.selected). End (). FIND (": Radio"). attr ("Checked",true); }); //style of default selected row when page is loaded$ ("table:radio:checked"). Closest ("tr")). addclass (options.selected); return This;//returns this to enable the method to be chained}) }) (jQuery);

Style:

Table{Border:1px Gray Solid;width:500px;Height:400px;text-align:Center;margin:0 Auto; }. Odd{Background-color:Gainsboro;}. Even{Background-color:#FFFFEE}. Selected{Background-color:Gold}

Html:

<Table>        <thead>        <TR>            <th></th>            <th>Name</th>            <th>Gender</th>            <th>Temporary land</th>        </TR>        </thead>        <tbody>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        <TR>            <TD><inputtype= "Radio"name= "Radio"></TD>            <TD>1</TD>            <TD>2</TD>            <TD>3</TD>        </TR>        </tbody>    </Table>

The code in <script>

$ (function() {            $ ("table"). Alterbgcolor ();//Call plugin, you can make your own style, with the "{}" object parameters of the way to pass        });

Note: The page needs to be first introduced into the jquery library

  The jquery selector may match 1 or more elements, so the plug-in must consider these cases. You can call the each () method inside the plug-in to traverse the matching element and then execute the appropriate method, which in turn references each DOM element

The following jquery code shows:

;(function($) {    $.fn.extend ({        function(options) {            return  this. each (function() {                /// here Place the plug-in code             } );        }    });}) (jQuery);)

jquery table interlaced color plug-in

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.