我创建一个表与2行的PHP文件和一个按钮上的每个最后<td>
获得TD的价值:尝试当我按下一个按钮
<table id="filterTableMsg" border="1" class="TF">
<tbody><tr><th>Message Title</th><th>Message</th><th>Schedule Date</th><th>share</th> </tr>
<tr class="row_hover">
<td>hello</td>
<td>hello message</td>
<td>2014-04-09 00:11:51</td>
<td><button id="FBshare">share it!</button></td>
</tr>
<tr class="row_hover">
<td>hello again</td>
<td>hello new message</td>
<td>2014-04-08 10:15:21</td>
<td><button id="FBshare">share it!</button></td>
</tr>
</tbody>
</table>
当我按下一个按钮(id="FBshare"
)我需要获取行索引,然后使用jQuery获取cell [0],cell [1]和cell [2]的值。
我尝试用这个代码来解决这个问题,但它返回“未定义”:
$(function() {
/*when i click on the FBshare button*/
$(document).on('click', '#FBshare', function(e){
e.preventDefault();
var mytable = $('#filterTableMsg tr:eq(1) td');//for example to get the 2nd row
alert(mytable.eq(2).html());//here i try to get the html of the 2nd cell but i get 'undifined
});
我可以通过编写此获得按钮的行的索引:
alert($(this).closest('tr').index()); // but I can't make them work all together.
有没有人面临相同或相似的问题?
请举个手
一个问题我看到的是,你有相同的ID(FBshare)多个元素。 Id的需要是独一无二的。 – Khan