Make a particular table interlaced (from sharp jquery)

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <Metaname= "Generator"content= "EditPlus" />    <title>To make a particular table interlaced</title>    <Scriptsrc= "Jquery-1.7.1.min.js"type= "Text/javascript"></Script>    <!--<script type= "Text/javascript" > (function () {alert ("functions have been called!) "); }) ();</script> -    <!--idea: 1. Get the table based on the table ID.        2. Get the <tbody> element in the table.    3. Get <tr> elements under the <tbody> element.    4. Loop out the <tr> elements obtained.    5. Divide the index value of the <tr> element by 2 and modulo, and then set a different background color based on the parity.  -</Head><Body>    <TableID= "TB">        <tbody>            <TR><TD>First line</TD><TD>First line</TD></TR>            <TR><TD>Second line</TD><TD>Second line</TD></TR>            <TR><TD>Third line</TD><TD>Third line</TD></TR>            <TR><TD>Line Four</TD><TD>Line Four</TD></TR>            <TR><TD>Line Five</TD><TD>Line Five</TD></TR>        </tbody>    </Table>    <Scripttype= "Text/javascript">        //Traditional methods:        //var item = document.getElementById ("TB");//Get an element with an ID of TB (table)        //var tbody = item.getelementsbytagname ("tbody") [0];//Gets the first TBODY element of a table        //var trs = Tbody.getelementsbytagname ("tr");//Get all the TR elements under the TBODY element        //For (var i = 0; i < trs.length; i++)//cyclic TR element        //{        //if (i% 2 = = 0)//modulo (take the remainder.) e.g. 0%2==0,1%2==1,2%2==0)        //    {        //Trs[i].style.backgroundcolor = "#888"; Change the background color of the TR element that matches the condition        //    }        //}        //jquery Method:        $('#tb tbody Tr:even'). CSS ("BackgroundColor", "#888"); //get the element with the ID of TB, then look for the tbody tag underneath it, and look for the TR element whose index value is even in tbody, changing its background color        //css ("property", "value"), the style used to set the jquery object    </Script></Body></HTML>

 

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.