使用 JQuery 按 id 隐藏表列
我需要使用 JQuery 隐藏/显示表列。找到答案并不难:经过一些研究,我发现了一些看起来像这样的东西:
$('#btnHide').click(function() {
$('td:nth-child(2),th:nth-child(2)').toggle();
});
效果很好,但有一个限制:你必须给出列号。
就我而言,事情变得更棘手:显示的列取决于您是谁(即简单用户:您只需看到第 1、3 和 5 列。Admid 用户:您可以看到所有列)
这是使用 php 规则设置的,以提高安全性。因此,我最终得到的“文章”列在管理员时为数字“3”,在用户时为数字“2”。提到的解决方案
=>我需要一个解决方案来使用列 ID 而不是列号。我环顾四周,但找不到答案。有人有主意吗?
谢谢
I need to hide / show table columns with JQuery. Not so hard to find an answer : after a few researches, i found something that look like that :
$('#btnHide').click(function() {
$('td:nth-child(2),th:nth-child(2)').toggle();
});
Works quite well, but has one constraint : you have to give the column number.
In my case, things get taugher : the displayed columns depend on who you are (i.e. simple user : you juste get to see column 1, 3 and 5. Admid user : you see all columns)
This is set with php rules for more security. So I end up with my column "article" with the number "3" when admin, and "2" when user. The solution mentionned
=> I need a solution to use columns ids instead of column number. I've looked around a bit, but I couldn't find an answer. Does anyone have an idea ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 id 来获取特定列的索引。
像这样的东西
将该索引与您已经找到的内容整合起来。
You can use the id to obtain the index of a particular column.
Something like
Integrate that index with what you've already found.