问题描述
您好我有一个基于db返回的数据的动态行数的表。我会在这里将问题硬编码为2行。对于每一行,我将有一个超链接,当点击时,表行记录将更新到db。我没有更新数据库部分的问题,但我不知道如何获取当前行的每个表格单元格的数据。以下是我到目前为止尝试的代码:
< table>
< tr>
< td>< a href =#onclick =getColumnValue(this);>点击我!< / a>< / td>
< td> 1< / td>
< td>一些文字1< / td>
< / tr>
< tr>
< td>< a href =#onclick =getColumnValue(this);>点击我!< / a>< / td>
< td> 2< / td>
< td>一些文字2< / td>
< / tr>
< tr>
< td>< a href =#onclick =getColumnValue(this);>点击我!< / a>< / td>
< td> 3< / td>
< td>一些文字3< / td>
< / tr>
< / table>
< script>
函数getColumnValue(e){
//我知道这里是对象类型但不确定如何更改它
var colValue = this.dataItem($(e.currentTarget)。最接近( TR));
//用于验证目的
alert(colValue);
}
< / script>
我无法移动 onclick =getColumnValue(this);
成tr元素。
什么我试过了:
1.在线查看解释或建议,但无济于事。
Hi I have a table with dynamic number of rows based on data returned from db. I will hardcoded my table into only 2 rows for the question here. For each row, i will have a hyperlink and when on click, the table row record will get updated into db. I have no problem on the updating db part but i would not sure on how to get each table cell's data on that current row. Below are my codes i have tried so far:
<table> <tr> <td><a href="#" onclick="getColumnValue(this);">Click Me!</a></td> <td>1</td> <td>Some Text 1</td> </tr> <tr> <td><a href="#" onclick="getColumnValue(this);">Click Me!</a></td> <td>2</td> <td>Some Text 2</td> </tr> <tr> <td><a href="#" onclick="getColumnValue(this);">Click Me!</a></td> <td>3</td> <td>Some Text 3</td> </tr> </table>
<script> function getColumnValue(e){ //i know here is the object type but would not sure on how to change it var colValue= this.dataItem($(e.currentTarget).closest("tr")); //for verification purposes alert(colValue); } </script>
I cannot move the
onclick="getColumnValue(this);"
into tr element due to some design limitation.
What I have tried:
1. Look online for explantion or suggestion but to no avail.
这篇关于如何在单击时获取当前表行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!