简体   繁体   English

最大化/最小化HTML表 <th> 使用jQuery

[英]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应该maximizeminimize

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.

相关问题 jQuery最小化和最大化HTML Div - JQuery Minimize & Maximize HTML Div 如何使用 jquery 和 animate.css 切换最大化/最小化? - How to toggle Maximize/Minimize using jquery & animate.css? 如何最小化/最大化jQuery对话框? - How to Minimize/Maximize jQuery Dialog? 使用javascript最小化和最大化文本 - minimize and maximize the text using javascript 如何最大化和最小化一个 div(没有 jquery 只有 javascript) - How to maximize and minimize a div (no jquery only javascript) 如何使用 javascript 或 jquery 在页面加载时禁用浏览器最小化、最大化和关闭按钮 - How to disable browser minimize, maximize and close button on page load using javascript or jquery 仅使用手指最小化和最大化地​​图-Android - minimize and maximize the map using fingers only - Android 在html表中,将每个数据行的第一个单元格更改为<th scope="row"> , 代替<td>元素,使用jQuery? - In html table, change first cell of each data row to <th scope="row">, instead of a <td> element, using jQuery? 最小化div最大化? 适用于所有div的javascript或jquery - minimize maximize the div ? javascript or jquery which works for all the div 为什么jQuery slideToggle在最小化/最大化div时不呈现动画/过渡? - Why jQuery slideToggle is not rendering animation/transition when minimize/maximize the divs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM