jquery Set table odd even color and row selected color style jquery set table odd even color and row selected color style

Source: Internet
Author: User

Query code

$ (funtion () {
Set even lines and odd lines
$ ("tbody>tr:odd"). AddClass ("ou"); Set style for odd rows (add Style Class)
$ ("Tbody>tr:even"). AddClass ("Dan"); Set style classes for even rows
$ ("Tbody>tr:has (: Checked)"). AddClass ("Ed"); Determines whether the row is selected (returns a Boolean type) to add a style class//has (: checked)) to return a bool value True/false

Search is selected has (: checked)
$ (' tbody>tr '). Click (function () {
var hased = $ (this). Hasclass (' Ed ');

if (hased)
{
$ (this). Removeclass ("Ed"). Find (": Input"). attr ("checked", false);
}
Else
{

$ (this). AddClass ("Ed"). Find (": Input"). attr ("Checked", true);
}

});
Traversing a specified trigger function

})

CSS code:

<style type= "Text/css" >
Table {border:0;border-collapse:collapse;}
TD {Font:normal 12px/17px arial;padding:2px;width:100px;}
th {font:bold 12px/17px
arial;text-align:left;padding:4px;border-bottom:1px solid #333;}
. Dan {background: #FC0}
. ou {background: #FFF}
. ed {background: #669; color: #fff;}
</style>

HTML Code

<body>
<table>
<thead>
<tr><th> </th><th> title </th><th> time </th><th> location </th></tr >
</thead>
<tbody>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 1</td><td>2011</td><td> Shanghai </td>
</tr>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 2</td><td>2012</td><td> Hangzhou </td>
</tr>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 3</td><td>2011</td><td> Jinan </td>
</tr>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 4</td><td>2012</td><td> Beijing </td>
</tr>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 5</td><td>2011</td><td> Wuhan </td>
</tr>
<tr>
<td><input type= "checkbox" name= "Choice" value= "" ></td>
<td>php100 Video 6</td><td>2012</td><td> Fuzhou </td>
</tr>

</tbody>
</table>
</body>

jquery Set table odd even color and row selected color style jquery set table odd even color and row selected color style

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.