html之table之多个tbody

[size=large][b]效果图:[/b][/size]


[img]http://dl2.iteye.com/upload/attachment/0119/4756/086f1e04-29eb-3617-975b-a7c24ab0de18.png[/img]


[size=large][b]代码:[/b][/size]



<!DOCTYPE html>
<html>
<head>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>


table, td, th {
border: 1px solid black;
border-top:none;
}
th{
border-top: 1px solid black;
}


th,td{
width: 100px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
table {
border-collapse: collapse;
}

th {
text-align: left;
}
.expand{
display:block;
border:1px solid black;
position:relative;
float:right;
margin-right:-53px;
background-color:#f2f2ff;
width:50px;
height:100%;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
cursor:pointer;
color:#456;
}
.expand:hover{
color:#888;
}

.tHide{
display:none;
}

h2>i{
color:brown;
}
</style>
</head>
<body>

<h2>The <i>tbody</i> Tag</h2>
<p>Use <b><i>multiple</i></b> tbody sections when rules are needed between groups of table rows:</p>

<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
</table>


<table>
<tbody>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100
<span class="expand">Detail</span>
</td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>
</table>


<table>
<tbody>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>
</table>


<table>
<tbody>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>
</table>


<table>
<tbody>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>
</table>

<script>

$(function(){

$("tbody span.expand").click(function(){

var tbody =
$(this)
.parent() // td
.parent() // tr
.parent() // tbody
.siblings('tbody');

tbody
//.slideToggle("slow");
//.toggleClass("tHide");
.fadeToggle("fast","swing");
});

});


</script>

</body>
</html>





代码二:




<!DOCTYPE html>
<html>
<head>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>


table, td, th {
border: 1px solid black;
border-top:none;
}
th{
border-top: 1px solid black;
}


th,td{
width: 100px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
table {
border-collapse: collapse;
}

th {
text-align: left;
}
.expand{
display:block;
border:1px solid black;
position:relative;
float:right;
margin-right:-53px;
background-color:#f2f2ff;
width:50px;
height:100%;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
cursor:pointer;
color:#456;
}
.expand:hover{
color:#888;
}

.tHide{
display:none;
}

h2>i{
color:brown;
}
</style>
</head>
<body>

<h2>The <i>tbody</i> Tag</h2>
<p>Use <b><i>multiple</i></b> tbody sections when rules are needed between groups of table rows:</p>

<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
</thead>


<!-- 1. tbody -->
<tbody>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100
<span class="expand">Detail</span>
</td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>


<!-- 2. tbody -->
<tbody>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>

<!-- 3. tbody -->
<tbody>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>


<!-- 4. tbody -->
<tbody>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250<span class="expand">Detail</span></td>
</tr>
</tbody>
<tbody class="tHide">
<tr>
<td>1.0</td>
<td>2.0</td>
<td>3.0</td>
</tr>
<tr>
<td>2.0</td>
<td>3.0</td>
<td>4.0</td>
</tr>
</tbody>

</table>


<script>

$(function(){

$("tbody span.expand").click(function(){

var tbody =
$(this)
.parent() // td
.parent() // tr
.parent() // tbody
.next();

tbody
//.slideToggle("slow");
//.toggleClass("tHide");
.fadeToggle("fast","swing");
});

});


</script>

</body>
</html>





引用:

[url]http://stackoverflow.com/a/3076721/2893073[/url]

[url]http://www.w3.org/TR/xhtml1/dtds.html[/url]


--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值