表格操作

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>操作表格-选择器</title>
<script type="text/javascript" src="class library/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
	$('.tab1 tbody tr:even,.tab2 tbody tr:even,.tab3 tbody tr:even').addClass('odd');
	$('.tab1 tbody tr,.tab2 tbody tr,.tab3 tbody tr').hover(function(){
		$(this).addClass('highlight');
	},function(){
		$(this).removeClass('highlight');
	});
	$('.tab1 tbody tr').click(function(){
		$(this).toggleClass('selected');
	});
	$('.tab2 input[type=checkbox]:checked,.tab3 input[type=radio]:checked').parents('tr').addClass('selected');
    $('.tab2 tbody tr').click(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
			$(this).find('input[type=checkbox]').removeAttr('checked');
		}else{
			$(this).addClass('selected');
			$(this).find('input[type="checkbox"]').attr('checked','checked');
		}
	});
    $('.tab3 tbody tr').click(function(){
		    $(this).siblings().removeClass('selected');
			$(this).addClass('selected');
			$(this).find('input[type="radio"]').attr('checked','checked');
	});
});
</script>
<style type="text/css">
h1			{ font:bold 20px/26px Arial;}
table		{ border:0;border-collapse:collapse;}
td	{ font:normal 12px/17px Arial;padding:2px;width:100px;}
th			{ font:bold 12px/17px Arial;text-align:left;padding:4px;border-bottom:1px solid #333;}
tr.odd		{ background:#FFF3BF;}
tr.highlight	{ background:#6F4DFF;}
tr.selected		{ background:#aaaaaa;color:#fff;}
</style>


</head>

<body>
<h1>Demo1--隔行,滑动,点击 变色.</h1>
<table class="tab1">
<thead>
<tr>
	<th>姓名</th>
	<th>性别</th>
	<th>暂住地</th>
</tr>
</thead>
<tbody>
<tr>
 	<td>张山</td>
	<td>男</td>
	<td>浙江宁波</td>
</tr>
<tr>
	<td>李四</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td>王五</td>
	<td>男</td>
	<td>湖南长沙</td>
</tr>
<tr>
	<td>找六</td>
	<td>男</td>
	<td>浙江温州</td>																												
</tr>
<tr>
	<td>Rain</td>
	<td>男</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td>MAXMAN</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>
</tbody>
</table>


<!-- demo2 -->
<h1>Demo2--隔行,滑动,点击 变色.+  多选框选中的行 变色.</h1>
<table class="tab2">
<thead>
<tr>
	<th> </th>
<th>姓名</th>
	<th>性别</th>
	<th>暂住地</th>
</tr>
</thead>
<tbody>
<tr>
	<td><input type="checkbox" name="tablechoice1" value="" /></td>
  	<td>张山</td>
	<td>男</td>
	<td>浙江宁波</td>
</tr>
<tr>
	<td><input type="checkbox" name="tablechoice1" value="" /></td>
 		<td>李四</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td><input type="checkbox" name="tablechoice1" value="" checked/></td>
 			<td>王五</td>
	<td>男</td>
	<td>湖南长沙</td>
</tr>
<tr>
	<td><input type="checkbox" name="tablechoice1" value="" /></td>
 	<td>找六</td>
	<td>男</td>
	<td>浙江温州</td>	
</tr>
<tr>
	<td><input type="checkbox" name="tablechoice1" value="" /></td>
 		<td>Rain</td>
	<td>男</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td><input type="checkbox" name="tablechoice2" value="" checked/></td>
	<td>MAXMAN</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>

</tbody>
</table>



<!-- demo3 -->
<h1>Demo3--隔行,滑动,点击 变色.+  单选框选中的行 变色.</h1>
<table class="tab3">
<thead>
<tr>
	<th> </th>
<th>姓名</th>
	<th>性别</th>
	<th>暂住地</th>
</tr>
</thead>
<tbody>
<tr>
	<td><input type="radio" name="tablechoice" value=""/></td>
  	<td>张山</td>
	<td>男</td>
	<td>浙江宁波</td>
</tr>
<tr>
	<td><input type="radio" name="tablechoice" value="" /></td>
 		<td>李四</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td><input type="radio" name="tablechoice" value="" checked /></td>
 			<td>王五</td>
	<td>男</td>
	<td>湖南长沙</td>
</tr>
<tr>
	<td><input type="radio" name="tablechoice" value="" /></td>
 	<td>找六</td>
	<td>男</td>
	<td>浙江温州</td>	
</tr>
<tr>
<td><input type="radio" name="tablechoice" value="" /></td>
 		<td>Rain</td>
	<td>男</td>
	<td>浙江杭州</td>
</tr>
<tr>
	<td><input type="radio" name="tablechoice" value="" /></td>
	<td>MAXMAN</td>
	<td>女</td>
	<td>浙江杭州</td>
</tr>

</tbody>
</table>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值