示例代码
<script>
function init()
{
var the_table=document.getElementById("mytable");
console.log(the_table.rows.length);
}
window.onload=init;
function go(the_row)
{
var the_table=document.getElementById("mytable");
rowIndex=the_row.rowIndex; //拿到被点击行的行号,注意行号是从0开始的
rowID=the_row.id; //可以拿到被点击行的id
console.log(the_table.rows[rowIndex].cells[0].innerHTML); //拿到指定行的第一个cell的HTML
console.log(the_table.rows[rowIndex].cells[1].childNodes[0].value); //拿到指定行的第二个cell的第一个子对象元素的值
the_table.deleteRow(rowIndex); //删除被点击行
}
</script>
<html>
<link href="style.css" type="text/css" rel="stylesheet" />
<table id="mytable">
<tr onclick="go(this)" id="id001"><td>a</td><td><input type="text" value="1"/></td></tr>
<tr onclick="go(this)" id="id002"><td>b</td><td><input type="text" value="2"/></td></tr>
<tr onclick="go(this)" id="id003"><td>c</td><td><input type="text" value="3"/></td></tr>
<tr onclick="go(this)" id="id004"><td>d</td><td><input type="text" value="4"/></td></tr>
</table>
</html>
运行后的界面
点击第4行号调试窗口界面