gpt4 book ai didi

jquery - 使用 jQuery 隐藏表格列

转载 作者:行者123 更新时间:2023-12-01 00:24:47 24 4
gpt4 key购买 nike

这个问题被问过很多次了,我知道,但这次不一样!我做了这个:

enter image description here

当你点击减号图标时,该列应该消失,这适用于 php,但代码很困惑,我想用 jQuery 来实现它,我发现其他一些线程向我展示了这一点:

$("#minus").click(function() {
$("#table td:nth-child(2),th:nth-child(2)").hide();
});

过了一会儿我想出了这个:

var num = $("#columnid").index();    
$("#table td:nth-child("+ num +"),th:nth-child("+ num +")").hide();

这有点工作,但我需要用 onclick="jquery_function();" 函数调用它,并让 php 插入每个 header 的 id,但这可能吗?或者这样做的其他方法是什么?我被困住了!

这样做了:

$(".minus").click(function() {
var num = $(this).parent().index() + 1;
$("#table td:nth-child("+ num +"),th:nth-child("+ num +")").fadeOut(250);
});

弄清楚后看起来很简单,Jeroen 是对的。 :) 我唯一不明白的是为什么你需要(“th”),无论有没有。谢谢!

最佳答案

看起来你已经快完成了。您可以做的是将其包装在函数中并将事件处理程序附加到表标题单元格中的按钮:

$("th .button").click(function(){
var num = $(this).parents("th").index(); // untested, but something like this should do it
$("#table td:nth-child("+ num +"),th:nth-child("+ num +")").hide();
return false;
}

关于jquery - 使用 jQuery 隐藏表格列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com