最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

FoldingUnfolding table with HTMLJavascript - Stack Overflow

programmeradmin1浏览0评论

I have a table which is pretty big, so I need a way to unfold it all the time, and unfold it only necessary.

How can I do that with HTML? Do I need Javascript for this? If so, what's the code for this?

I have a table which is pretty big, so I need a way to unfold it all the time, and unfold it only necessary.

How can I do that with HTML? Do I need Javascript for this? If so, what's the code for this?

Share Improve this question asked Jul 24, 2010 at 16:27 prosseekprosseek 191k227 gold badges583 silver badges885 bronze badges 2
  • Can you give some sort of example? Im not too sure what you mean by folding/unfolding a table – barrylloyd Commented Jul 24, 2010 at 16:42
  • 1 Why don't you add paging instead of folding / unfolding? That way you could keep the data cached and display only the current page. Then you wouldn't have to worry about poor performance. – Dan Stocker Commented Jul 24, 2010 at 16:45
Add a ment  | 

3 Answers 3

Reset to default 2

If you will use jquery you can check the code below.

In css:

.collapsed-table tr {
  display: none;
}

In html:

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.4/jquery.min.js"></script> 
<table class="collapsed-table">
   <caption>Expand/collapce</caption> 
   <tr>
       <td></td>
   </tr>
   ....
</table>

<script type="text/javascript">
$('.collapsed-table > caption').click(function() {
   $(this).toggleClass('collapsed-table');
})
</script>

Keep the header (thead) visible at all times and toggle the visibility of the body (tbody) when the user clicks on the folding button.

Using jQuery:

$('#foldbutton').click(function()
{
$('tbody').toggle();
});

I know it's an old question but others can have the same problem and no one have provided a plete solution, so if you want to fold / unfold something with an animation, I developed a script named TextShower that allows you to do that. It's highly customizable and you can edit its source freely. Hope this helps :)

发布评论

评论列表(0)

  1. 暂无评论