【发布时间】:2017-01-02 03:46:25
【问题描述】:
<table border="1px" id="myTable" cols="3">
<tr onclick="function1(this)">
<td id="td1" >Cell 1</td>
<td id="td2" >Cell 2</td>
<td id="td3" >Cell 3</td>
</tr>
<tr onclick="function1(this)">
<td id="td1" >Cell 1</td>
<td id="td2" >Cell 2</td>
<td id="td3" >Cell 3</td>
</tr>
<tr onclick="function1(this)">
<td id="td1" >Cell 1</td>
<td id="td2" >Cell 2</td>
<td id="td3" >Cell 3</td>
</tr>
<tr onclick="function1(this)">
<td id="td1" >Cell 1</td>
<td id="td2" >Cell 2</td>
<td id="td3" >Cell 3</td>
</tr>
</table>
<script language="JavaScript">
function function1(elem) {
alert("Cell Index :"+ elem.rowIndex);
}
</script>
我想要使用 Javascript 的特定 tr 索引的 td 值实际上我正在创建一个表,当我单击特定 tr 的 td 中的编辑按钮转换为文本框并编辑表时,该表在 tr 末尾具有编辑功能。
【问题讨论】:
-
elem.cells[1].textContent -
...并摆脱那些重复的 ID。它们应该是独一无二的。
标签: javascript jquery html html-table