Home  >  Article  >  Web Front-end  >  js tr controls the hiding and display of the tbody below_javascript skills

js tr controls the hiding and display of the tbody below_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:02:171578browse

The core code used is
function $(obj){
return document.getElementById(obj);
}
window.onload = function(){
var table = document.getElementById(" myTable");
//If a click occurs in the table area
table.onclick = function(e){
var e = window.event||e,target = e.srcElement||e .target;

//Get tr
while(target.tagName.toLowerCase() != "tr"){
target = target.parentNode;
}

var i = target.rowIndex;
//Click on a single row of Tr to control the hiding and display of tr 1

if(i%2 == 0){
var nrs = table .rows[i 1].parentNode.style;
nrs.display = nrs.display == "none"?"":"none";
}
}
}

Statement:
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