我試圖使用每個單元格中的按鈕來獲取所選行的列的值。這裏是我的Jquery,使用JQuery獲取表中選定行和列的值
$('.sampleBtn').click(function(){
var row = $(this).closest('td');
var col = $(this).parent().children().index($(this));
var id = row.find('.mainId').val();
var level = row.find('.level').val();
alert("Main ID "+id+" Job ID "+col+" Level "+level);
});
它正常工作時,我用了一個可點擊的細胞,但是當我使用一個按鈕,它總是說,即時通訊在第3列,即使我點擊其他單元格的按鈕。
鑑於表的TBODY,
<?php foreach($mains as $temp): ?>
<tbody>
<tr>
<td>
<input type="hidden" value="<?php echo $temp->Main_ID; ?>"/><?php echo $temp->Main_Name; ?>
</td>
<td>
<select class="level">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<input type="hidden" class="mainId" value="<?php echo $temp->Main_ID; ?>" />
<input type="button" class="sampleBtn" value="Update" />
</td>
</tr>
</tbody>
<?php endforeach; ?>
哦,那就是我忘了..謝謝 :) – Vhey