[英]jQuery selector for second column in HTML table row
我的代碼的目的是將選定HTML表行中的數據添加到JavaScript數組,如果未選中該行,則將其刪除。
https://jsfiddle.net/nicktry/h1636ram/
我目前有兩個問題:
我無法正確獲取jQuery選擇器以將表數據添加/刪除到數組中。
$('table tbody tr').click(function(event) { if (event.target.type !== 'checkbox') { $(':checkbox', this).trigger('click'); } $("input[type='checkbox']").change(function(e) { if($(this).is(":checked")){ $(this).closest('tr').addClass("selected_row"); addJob(document.getElementById('jobs'), $(this).closest('tr td:nth-child(2)').text()); }else{ $(this).closest('tr').removeClass("selected_row"); removeJob(document.getElementById('jobs'), $(this).closest('tr td:nth-child(2)').text()); } }); });
非常感謝stackoverflow社區的智慧!
您內部不應有兩個事件。
移動這個
$("input[type='checkbox']").not('#check_all').change(function (e) {
});
在外面
$('table tbody tr').click(function(event) {
});
改變這個
$(this).closest('tr td:nth-child(2)').text()
對此
$(this).parent().next().text()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.