如何用javascript获取表格中一行的值

来源:百度知道 编辑:UC知道 时间:2024/04/29 10:14:33

1、简单的,表格中的一行添加id属性

var item=document.getElementById("id");

2、在行本身绑定方法将自身作为参数传递

<html>
<head>
<script type = 'text/javascript'>
var curRow;//全局行号
var curRowId; //选中行的记录信息的ID
var curColor;
function selectRow(tr){//tr行本身
curRow = tr;
curRowId = tr.id;
alert(tr.cells[0].innerText);
}
</script>
</head>
<body onload = "javascript:selectRow(1)">
<table border = "1 solid">
<tr onclick = "selectRow(this);">
<td>001</td>
<td>google</td>
</tr>
<tr onclick = "selectRow(this);">
<td>002</td>
<td>baidu</td>
</tr>
</table