Sharp jquery (Table,checkbox)

Source: Internet
Author: User
Tags javascript array

1. Table odd and even rows

1<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">2"http://www.w3.org/1999/xhtml">34<title></title>5<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>6<script type="Text/javascript">7Window.onload = function () {//page all elements loaded complete8     varItem = document.getElementById ("TB");//get an element with an ID of TB (table)9     varTbody = Item.getelementsbytagname ("tbody")[0];//gets the first TBODY element of a tableTen     varTRS = Tbody.getelementsbytagname ("TR");//gets all the TR elements under the TBODY element One      for(varI=0; i < trs.length;i++) {//Cyclic TR element A         if(i%2==0){//Take the mold. (Take the remainder. such as 0%2=0, 1%2=1, 2%2=0, 3%2=1) -Trs[i].style.backgroundcolor ="#888";//changes the background color of the TR element that matches the condition. -         } the     } - } -</script> - +<body> -<table id="TB"> +<tbody> A<tr><td> first line </td><td> first row </td></tr> at<tr><td> second row </td><td> second row </td></tr> -<tr><td> third row </td><td> third row </td></tr> -<tr><td> Line Fourth </td><td> line fourth </td></tr> -<tr><td> Line Fifth </td><td> line fifth </td></tr> -<tr><td> Line Sixth </td><td> line sixth </td></tr> -</tbody> in</table> -</body> to

2. CheckBox

1<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">2"http://www.w3.org/1999/xhtml">34<title></title>5<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>6<script type="Text/javascript">7Window.onload = function () {//page all elements loaded complete8     varBTN = document.getElementById ("btn");//get the element with ID btn (button)9Btn.onclick = function () {//to add an onclick event to an elementTen         vararrays =NewArray ();//Create an Array object One         varItems = Document.getelementsbyname ("Check");//gets a set of elements named Check (checkbox) A          for(i=0; i < items.length; i++) {//Loop This set of data -             if(Items[i].checked){//decide whether to select -Arrays.push (Items[i].value);//add eligible additions to the array. push () is a method in a JavaScript array . the             } -         } -Alert"the number of checks is:"+arrays.length); -     } + } -</script> + A<body> at<form method="Post"action="#"> -<input type="checkbox"Value="1"Name="Check" checked="checked"/> -<input type="checkbox"Value="2"Name="Check"/> -<input type="checkbox"Value="3"Name="Check" checked="checked"/> -<input type="Button"Value="the number you selected"Id="btn"/> -</form> in</body> -

Sharp jquery (Table,checkbox)

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.