Home >Web Front-end >JS Tutorial >js tr controls the hiding and display of the tbody below_javascript skills
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";
}
}
}