我有這樣的結構搶表格單元格中的文本
<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