JQuery line-Changing implementation code

Source: Internet
Author: User

In the past, we used js to write some table line-changing code. Let's see how to achieve line-changing using jquery. If you have any need to know, please refer

Html + jquery code

The Code is as follows: Copy code

<Style type = "text/css">
Body {
Font-size: 12px; text-align: center;
}
# TbStu {
Width: 260px; border: 1px solid #666; background-color: # eee;
}
# TbStu tr {
Line-height: 23px;
}
# TbStu tr th {
Background-color: # ccc; color: # fff;
}
# TbStu. trOdd {
Background-color: # fff;
}
</Style>
<Script src = "jQuery/jquery-1.9.1.js"> </script>
<Script type = "text/javascript">
/
// JQuery selector method (select the row of the table, and select a row)
$ (Function (){
$ ('# TbStu tr: nth-child (even)'). addClass ("trOdd ");
// When jQuery copies content to a DIV, it does not need to check whether the DIV exists.
// Condition ('{divmain'{.html ('this is a detection page ');
})
</Script>
</Head>
<Body>
<Table id = "tbStu" cellpadding = "0" cellspacing = "0">
<Tbody>
<Tr>
<Th> Student ID </th> <th> name </th> <th> gender </th>
</Tr>
<Tr>
<Td> 1001 </td> <td> Zhang Xiaoming </td> <td> male </td> <td> 320 </td>
</Tr>
<Tr>
<Td> 1002 </td> <td> Li Mingqi </td> <td> female </td> <td> 350 </td>
</Tr>
<Tr>
<Td> 1003 </td> <td> Zhang San </td> <td> male </td> <td> 150 </td>
</Tr>
</Tbody>
</Table>
</Body>

Js Writing Method

Common JS writing

The Code is as follows: Copy code

<Script>
Window. onload = function (){
Var oTb = document. getElementById ('tbtu ');
For (var I = 0; I <oTb. rows. length-1; I ++ ){
If (I % 2)
{
OTb. rows [I]. className = "trOdd ";
}
}
}
</Script>

<Body>
<Table id = "tbStu" cellpadding = "0" cellspacing = "0">
<Tbody>
<Tr>
<Th> Student ID </th> <th> name </th> <th> gender </th>
</Tr>
<Tr>
<Td> 1001 </td> <td> Zhang Xiaoming </td> <td> male </td> <td> 320 </td>
</Tr>
<Tr>
<Td> 1002 </td> <td> Li Mingqi </td> <td> female </td> <td> 350 </td>
</Tr>
<Tr>
<Td> 1003 </td> <td> Zhang San </td> <td> male </td> <td> 150 </td>
</Tr>
</Tbody>
</Table>

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.