使用Javascript切换表< tr>的display:none [英] Toggle a table <tr>'s display:none using Javascript

查看:158
本文介绍了使用Javascript切换表< tr>的display:none的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaScript制作表格行 display:none; 并再次点击按钮显示它。

I would like to use JavaScript to make a table row's display:none; and show it again on a click of a button.

推荐答案

普通JS - http:// jsfiddle。 net / mplungjan / t3mUq /

<script type="text/javascript">
function toggle(row) {
  if (isNaN(row)) row = document.getElementById(row); // id passed
  else row = document.getElementById('table1').rows[row]; // idx passed
  if (row) row.style.display=(row.style.display=='none')?'':'none';
  return false;
}

</script>
<a href="#" 
onClick="return toggle('row3')">Toggle row with ID row3</a>
<a href="#" 
onClick="return toggle(1)">Toggle 2nd row</a>

这篇关于使用Javascript切换表&lt; tr&gt;的display:none的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆