我有一个像这样的css表设置: 该表的CSS是: 当它站立时,两列在表格宽度占据的空间之间均匀分开。 我试图让第一列只有占据它的单元格的文本所需的宽度 该表是未知宽度,列/单元格也是如此。 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我有一个表,开始仅显示第一列:
#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");
});
将代码编辑为display:table-cell
不display: show
$(document).on('click', '#revealbutton', function() { $("<style> #tablegrid tr td:not(:first-child) { display:table-cell; } <\\/style>").appendTo("head"); });
#tablegrid tr td:not(:first-child) { display:none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="tablegrid"> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> </table> <button id="revealbutton">click me</button>
如果我理解正确,您可以做这样的事情
$("button").on("click", function(){ $("table tr td:not(:first-child)").hide(); });
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button>remove</button> <table> <tr> <td>adsa</td> <td>asdas</td> <td>adasd</td> <td>adad</td> <td>adasd</td> <td>asdasd</td> </tr> </table> </html>
试试这个,现在添加!
$('#revealbutton').on('click', function() {
$("<style> #tablegrid tr td:not(:first-child) { display:show; } </style>").appendTo("head");
});
让我知道是否有帮助!
您有正确的代码,但这只是Opening script
标签。 替换为: <style>/*A code here*/</style>
也许只是令人困惑? 除此之外,万事俱备。
$(document).on('click', '#revealbutton', function() { $("<style> #tablegrid tr td:not(:first-child) { display:show; } <\\/style>").appendTo("head"); });
#tablegrid tr td:not(:first-child) { display:none; }
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <table> <tr id=tablegrid> <td>1</td> <td>2</td> </tr> </table> </body> </html>
这应该是源代码。
希望这会有所帮助!
除非我误解了您的问题,否则我认为您已经使事情变得复杂了。 为什么不只使用.show()
$(document).on('click', '#revealbutton', function() {
$('#tablegrid tr td').show();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.