[英]Maximize/Minimize HTML Table by <th> USing JQuery
So I have a huge table with multiple table headers. 所以我有一个带有多个表头的巨大表。 I want to be able to maximize or minimize these headers using JQuery (or whatever works). 我希望能够使用JQuery(或任何可行的方法)最大化或最小化这些标头。 Here is an example table: 这是一个示例表:
<table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> </table>
Basically in this example, I would like two minimize/maximize buttons that interact apart from each other (if I hit one, the other is unchanged). 基本上在此示例中,我希望两个相互独立的最小化/最大化按钮(如果我按下一个,则另一个不变)。
You can give an id to the table like below 您可以为表格提供一个ID,如下所示
<table id="tb1">
Then you can use jQuery to hide the table on button click 然后您可以使用jQuery在单击按钮时隐藏表格
$("button#minimize").click(function(){
$("div#tb1").hide();
})
Similarly you can show the table on maximize button click. 同样,您可以在最大化按钮单击时显示表格。 Buttons should have the id maximize
and minimize
. 按钮的ID应该maximize
和minimize
。
Have you tried this? 你有尝试过吗?
http://www.w3schools.com/jquery/jquery_hide_show.asp http://www.w3schools.com/jquery/jquery_hide_show.asp
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
});
</script>
Basically this script above targets the id="hide"
基本上,以上这个脚本的目标是id="hide"
so when you click on the id element "hide" it starts up the Jquery function and hides the <p>
element. 因此,当您单击id元素“ hide”时,它将启动Jquery函数并隐藏<p>
元素。
Then the same way targets id="show"
然后以相同的方式定位id="show"
Just get a good read on it, it's quite simple to understand. 只需阅读一下,它就很容易理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.