纯粹的射手:
< 强 > HTML 强 >
<input type="checkbox" onclick="showhide(1, this)" checked="checked" /> Name<br />
<input type="checkbox" onclick="showhide(3, this)" checked="checked" /> Job<br />
<强 > JS 强 >
function showhide(column, elem){
if (elem.checked)
dp = "table-cell";
else
dp = "none";
tds = document.getElementsByTagName( tr );
for (i=0; i<tds.length; i++)
tds[i].childNodes[column].style.display = dp;
}
http://jsfiddle.net/NPHDE/3/" rel = “ no follow” >Pure JS小提琴例子
请考虑使用 javascription 库“ a href=”“http://jquery.com/” rel=“nofollow”>JQuery
< 强 > HTML 强 >
<input type="checkbox" data-col="1" checked="checked" /> Name<br />
<input type="checkbox" data-col="2" checked="checked" /> Job<br />
联合来文: 强>
$(function(){
$( :checkbox ).on( change , function(){
$( th, td , tr ).filter( :nth-child( + $(this).data( col ) + ) ).toggle();
});
});
http://jsfidd.net/FNFfpA/9/" rel = “ no follow” >jQuery Fiddle example