我有这样的结构抢表格单元格中的文本
<tr>
<th>some text0</th>
<th>some text1</th>
<th>some text2</th>
<td class="edit"><button>Edit</button></td>
</tr>
当单击编辑按钮,我想采取“一些文字0,1和2”,并将该表格内。
我试图使用JQuery Traversing中的方法,但没有成功。
一个例子
$(document.body).on('click', '.edit' ,function(){
var takeit = $(this).parent('tr th:eq(0)').html();
$('.a_input_for_my_form').val(takeit);;
});
另一个
$(document.body).on('click', '.edit' ,function(){
var father = $(this).parent('tr th:eq(0)');
var child = $(father).child('th').html();
$('.a_input_for_my_form').val(child);
});
谢谢!它的工作! – Ini