Home > Web Front-end > JS Tutorial > A simple way to control the odd and even row style of a form using js_javascript skills

A simple way to control the odd and even row style of a form using js_javascript skills

WBOY
Release: 2016-05-16 17:27:41
Original
1085 people have browsed it

1. If you use JQuery, you can directly copy the code of JQuery

. The code is as follows:

 $( "tr:odd").addClass("clazzName");
 $("tr:even").addClass("clazzName");

2. If you are using pure js
1. Get the table tag first, var table = document.getElementById()
2. Then get the tbody tag inside var tbody = table.getElementsByTagName("tbody")[0]
3. Get it again tr tag var trs = tbody.getElementsByTagName("tr")
 4. Then iterate trs
Copy code The code is as follows:

for(var i=0; i
if(i%2==0){
trs[i].style.backgroundColor="red";
} else{
 trs[i].style.backgroundColor="blue";
 }
 }

  It is necessary to obtain the tbody tag. Although you did not write it, the browser When compiling the table,
will be automatically added. All tr ​​tags are in the tbody.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template