Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 切换表的显示:不是第一列_Javascript_Jquery_Css - Fatal编程技术网

Javascript 切换表的显示:不是第一列

Javascript 切换表的显示:不是第一列,javascript,jquery,css,Javascript,Jquery,Css,我有一个表格,一开始只显示第一列: #tablegrid tr td:not(:first-child) { display:none; } 单击按钮时,如何显示所有其他列 以下是我尝试过的: $(document).on('click', '#revealbutton', function() { $("<style> #tablegrid tr td:not(:first-child) { display:show; } <\/style>").ap

我有一个表格,一开始只显示第一列:

#tablegrid tr td:not(:first-child) {
  display:none;
}
单击按钮时,如何显示所有其他列

以下是我尝试过的:

  $(document).on('click', '#revealbutton', function() {
    $("<style> #tablegrid tr td:not(:first-child) { display:show; } <\/style>").appendTo("head");
  });
$(文档)。在('click','revealbutton',函数()上{
$(“#tablegrid tr td:not(:first child){display:show;}”).appendTo(“head”);
});

如果我理解正确,您可以制作这样的东西

$(“按钮”)。在(“单击”,函数(){
$(“表tr td:not(:first child)”).hide();
});

去除
adsa
阿斯达斯
阿达斯德
阿达德
阿达斯德
asdasd

试试这个,现在正在追加

 $('#revealbutton').on('click', function() {
    $("<style> #tablegrid tr td:not(:first-child) { display:show; } </style>").appendTo("head");
  });
$('revealbutton')。在('click',function()上{
$(“#tablegrid tr td:not(:first child){display:show;}”).appendTo(“head”);
});
如果有帮助,请告诉我

您有正确的代码, 但这只是开头的
脚本
标记。 将其替换为:
/*此处的代码*/
也许这只是让人困惑? 除此之外,一切都很好

$(文档)。在('click','revealbutton',函数()上{
$(“#tablegrid tr td:not(:first child){display:show;}”).appendTo(“head”);
});
#tablegrid tr td:not(:第一个孩子){
显示:无;
}

1.
2.

将代码编辑为
显示:表格单元格
显示:显示

$(文档)。在('click','revealbutton',函数()上{
$(“#tablegrid tr td:not(:first child){display:table cell;}”).appendTo(“head”);
});
#tablegrid tr td:not(:第一个孩子){
显示:无;
}

1.
2.
3.
4.

单击我
除非我误解了你的问题,否则我认为你把事情复杂化了。为什么不直接使用.show()呢


它在

中起作用,这是一个提议,还是你错过了?在脚本示例中,您打开了一个
script
标记并关闭了一个
style
标记,第一个标记中必须是
style
?修复了该问题。但是仍然不能同时使用两个样式标记为什么要将样式附加到头部?为什么不直接使用
$('#tablegrid tr td').show()?我认为您的代码片段与OP的要求相反。我认为
.hide()
应该是
.show()
,除第一行外,其他所有行都应该隐藏起来。
$(document).on('click', '#revealbutton', function() {
    $('#tablegrid tr td').show();
});