下面是代碼(需要jquery.cookie.js才能工作)。 幾乎所有的功勞歸功於Toby Pitman。我所做的只是使他的可摺疊面板概念適用於桌子內部。
<html>
<head>
<style>
td {padding: 5px;}
.flip {cursor:pointer;}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".flip").addClass("active");
var flips = $(".flip").length;
for (c=0; c<=flips; c++){
var cvalue = $.cookie("panel" + c);
if (cvalue == 'closed' + c) {
$(".section").eq(c).css({display:"none"});
$(".section").eq(c).prev().removeClass('active').addClass('inactive');
};
};
$(".flip.active").toggle(
function(){
var num = $(".flip").index(this);
var cookieName = "panel" + num;
var cookieValue = "closed" + num;
$(this).closest("tbody").next(".section").slideUp(250);
$(this).removeClass("active");
$.cookie(cookieName, cookieValue, {path: '/', expires: 10});
},
function(){
var num = $(".flip").index(this);
var cookieName = "panel" + num;
$(this).closest("tbody").next(".section").slideDown(250);
$(this).addClass("active");
$.cookie(cookieName, null, {path: '/', expires: 10});
});
$(".flip.inactive").toggle(
function(){
var num = $(".flip").index(this);
var cookieName = "panel" + num;
$(this).closest("tbody").next(".section").slideDown(250);
$(this).addClass("active");
$(this).removeClass("inactive");
$.cookie(cookieName, null, {path: '/', expires: 10});
},
function(){
var num = $(".flip").index(this);
var cookieName = "panel" + num;
var cookieValue = "closed" + num;
$(this).closest("tbody").next(".section").slideUp(250);
$(this).removeClass("active");
$.cookie(cookieName, cookieValue, {path: '/', expires: 10});
});
});
</script>
</head>
<body>
<table id="main_table">
<thead>
<tr class="firstline">
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
</tr>
</thead>
<tbody class="flip">
<tr style="background-color:green; color:white">
<td colspan="4"> Section 1 </td>
</tr>
</tbody>
<tbody class="section">
<tr>
<td>item 111</td>
<td>item 112</td>
<td>item 113</td>
<td>item 114</td>
</tr>
<tr>
<td>item 121</td>
<td>item 122</td>
<td>item 123</td>
<td>item 124</td>
</tr>
<tr>
<td>item 131</td>
<td>item 132</td>
<td>item 133</td>
<td>item 134</td>
</tr>
</tbody>
<tbody class="flip">
<tr style="background-color:green; color:white">
<td colspan="4"> Section 2 </td>
</tr>
</tbody>
<tbody class="section">
<tr>
<td>item 211</td>
<td>item 212</td>
<td>item 213</td>
<td>item 214</td>
</tr>
<tr>
<td>item 221</td>
<td>item 222</td>
<td>item 223</td>
<td>item 224</td>
</tr>
<tr>
<td>item 231</td>
<td>item 232</td>
<td>item 233</td>
<td>item 234</td>
</tr>
</tbody>
<tbody class="flip">
<tr style="background-color:green; color:white">
<td colspan="4"> Section 3 </td>
</tr>
</tbody>
<tbody class="section">
<tr>
<td>item 311</td>
<td>item 312</td>
<td>item 313</td>
<td>item 314</td>
</tr>
<tr>
<td>item 321</td>
<td>item 322</td>
<td>item 323</td>
<td>item 324</td>
</tr>
<tr>
<td>item 331</td>
<td>item 332</td>
<td>item 333</td>
<td>item 334</td>
</tr>
</tbody>
</table>
</body>
</html>
來源
2011-03-29 14:24:00
CCC
@ CCC - >太棒了!至少BRAVO解決你自己的問題!我相信有人會覺得這很有用!願原力與你同在! ;)P.S. - >順便說一下是一個偉大的代碼! Thx與社區分享 – 2011-03-15 20:31:02
您能否將您的答案移出問題並轉化爲答案(您可以回答自己的問題),然後接受答案? – 2011-03-24 06:24:17
好點,薩米爾。完成。 – CCC 2011-03-29 14:24:38