我有一张表,我想给用户选择的能力。我在行的开头添加了一个按钮value =“Update”,并分配了一个onclick值。我的问题是我想从行中发送其他项目(在同一行上的td> s)到按钮所调用的函数。使用按钮传递td数据
如何从按钮所在行获取信息?我想将“名称”和“上次更新时间”传递给按钮调用的函数。我尝试使用以下:
$("#Report input[name=btn_id]").closest('td').attr('text')
但它返回“不确定”,这我并不惊讶,因为我认为这是由于它不知道从拉什么行的表。
下面是表的视图: 下面是表后面的代码:
<table align="center" border="1" class="report" id="report">
<thead>
<tr>
<th width="75">Update</th>
<th width="500">Name</th>
<th width="50">Info</th>
<th width="100">location</th>
<th width="100">Last Update Time</th>
</tr>
</thead>
<tbody>
<tr class="parent" id="other_app">
<td align="center">
<input type="button" name="btn_id" value="Update" onclick="UpdateRec(d1)">
</td>
<td name="App_Name">Test1</td>
<td align="center">None</td>
<td align="center">Desktop</td>
<td align="center">2014-06-30 18:22:39</td>
</tr>
<tr class="parent" id="other_app">
<td align="center">
<input type="button" name="btn_id" value="Update" onclick="UpdateAppRec(d1)">
</td>
<td name="App_Name">Test1</td>
<td align="center">None</td>
<td align="center">Server</td>
<td align="center">2014-03-30 16:20:15</td>
</tr>
</tbody>
任何帮助,将不胜感激。
'attr('text')'不起作用。你可以使用'.text()'。你也可以使用'$(this)'而不是使用选择器,因为'this'的值将是按钮上下文。 – bencripps 2014-09-19 16:47:08
如何将它们添加为按钮调用的JavaScript函数的参数? – andrex 2014-09-19 17:04:53