我有一個表格。每列在頂部都有一個按鈕。如果列中的以下td元素中有內容,則隱藏該按鈕。如果沒有,那麼顯示按鈕和onClick添加類活動太td元素。如果表格元素上滿足條件,則進行切換
$(document).ready(function(){
$('.button-fill').on("click", function() {
var i=$(this).parent().index();
if($(this).closest("tr").siblings().find("td:eq("+i+")").text()=="")
$(this).hide();
else
$(this).show();
});
<!-- Fill in the td -->
$('.button-fill').on("click", function() {
var i=$(this).parent().index();
$(this).closest("tr").siblings().find("td:eq("+i+")").addClass("active");
//});
});
});
我創建了一個的jsfiddle。我不知道我做錯了什麼?謝謝
嗨,你的要求我不清楚。如果任何一列的文本比最初的文字不想顯示「填充」按鈕?並且如果用戶點擊「填寫」按鈕,您將分配所有TD「活動」類?我對麼? – Prateek