js怎么获取表格中的值

如题所述

第1个回答  2016-12-23
1、简单的,表格中的一行添加id属性

1

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

<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)本回答被网友采纳