我有一張表,我想給用戶選擇的能力。我在行的開頭添加了一個按鈕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