Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 隐藏特定表的第n个子项_Javascript_Jquery_Html Table_Css Selectors - Fatal编程技术网

Javascript 隐藏特定表的第n个子项

Javascript 隐藏特定表的第n个子项,javascript,jquery,html-table,css-selectors,Javascript,Jquery,Html Table,Css Selectors,我一页有两张桌子。如何解决第二个问题,即运行显示/隐藏第n个子函数的问题 我无意中试图通过将id引用添加到'td:nth child…'的开头来处理特定的表。 ... var x = document.getElementById("tatt"); $(x.'td:nth-child(3),th:nth-child(3)').hide(); ... 差不多 $('#tatt').find('td:nth-child(3), th:nth-child(3)').hide(); 或 (顺便说一句

我一页有两张桌子。如何解决第二个问题,即运行显示/隐藏第n个子函数的问题

我无意中试图通过将id引用添加到
'td:nth child…'的开头来处理特定的表。

...
var x = document.getElementById("tatt");
$(x.'td:nth-child(3),th:nth-child(3)').hide();
...
差不多

$('#tatt').find('td:nth-child(3), th:nth-child(3)').hide();


(顺便说一句,如果您使用jQuery进行DOM操作,实际上也不需要调用
findElementById
方法。只需坚持
$(/*selector*/)

就可以在每个逗号分隔的组中按id在选择器前面。试试看

$('#tatt td:nth-child(3), #tatt th:nth-child(3)').hide();

注意:当您已经有了jQuery时,为什么要使用
getElementById()
呢?

是否在每行中隐藏第n个3的子项?总体思路是使用按钮隐藏表格的整列。对不起,我认为“无知”注释足以解释;)对不起,快速跟进:我可以根据,在这种情况下,请指定id,而不是'nth'?@sukebe7,如
td#math
。。。。尝试
$('tatt td#math,#tatt th:nth child(3)')。隐藏()@sukebe7,还有一件事,我想在td中使用id可能会产生一些意想不到的结果。相反,您应该使用类来标识多个元素……我能够动态地构建按钮以及PHP生成的表。到目前为止,第n种方法正在发挥作用。不过,我以后会用你的建议来证明谢谢
$('#tatt td:nth-child(3), #tatt th:nth-child(3)').hide();