87,994
社区成员
发帖
与我相关
我的任务
分享
<table id="t">
<tr>
<td>line No.</td>
<td>title1</td>
<td>title2</td>
<td>title3</td>
</tr>
<tr>
<td>1</td>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>2</td>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
</table>
<button onclick="f1()">隐藏第1行</button>
<button onclick="f2()">隐藏第2行 第3列</button>
<button onclick="f3()">看table一共有几个cell</button>
<button onclick="f4()">隐藏第11个cell(2行 3列)</button>
<script>
var table = document.getElementById("t");
function f1(){
table.rows[1].style.display = "none";
}
function f2(){
table.rows[2].cells[2].style.display = "none";
}
function f3(){
alert(table.cells.length + ",包含了title的所有cell");
}
function f4(){
table.cells[10].style.display = "none";
}
</script>