Jquery实现table行数的增加,删除,实现指定行数的添加等应用~~~~!!!!

先看下效果图(帮助大家理解实现哪些功能):




先上Html代码:

<body>
	<div class="center">
    	<a id="addbottom">添加一行到底部</a>            <a id="addtop">添加一行到顶部</a>
        <table border="1px" width="100%">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>姓名</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            	
            </tbody>
            
        </table>
	</div>
</body>

css代码:

<style type="text/css">
	.center{
		margin-left:auto;
		margin-right:auto;
		width:600px;
		margin-top:100px;
	}
	table{
		border:1px solid #000;
		border-collapse:collapse;
		}
	thead{
		background-color:#C03;
		color:#FFF;}
		a{
			cursor:pointer;}
</style>


jquery:


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

	$(document).ready(function(){
		var i = 1;
		$("#addbottom").click(function(){
			
			$("<tr><td>"+i+"</td><td></td><td><a id='del'>删除此行</a>  <a id='addup'>向上添加一行</a>  <a id='adddown'>向下添加一行</a></td></tr>").appendTo($("tbody"));
		i++;
			});
		$("#addtop").click(function(){
			
			$("<tr><td>"+i+"</td><td></td><td><a id='del'>删除此行</a>  <a id='addup'>向上添加一行</a>  <a id='adddown'>向下添加一行</a></td></tr>").prependTo($("tbody"));
		i++;
			});
			$("#del").live("click",function(){
				$(this).parent("td").parent("tr").remove();
				});
			$("#addup").live("click",function(){
				
				$(this).parent("td").parent("tr").before($("<tr><td>"+i+"</td><td></td><td><a id='del'>删除此行</a>  <a id='addup'>向上添加一行</a>  <a id='adddown'>向下添加一行</a></td></tr>"));
				i++;
				});
				
			$("#adddown").live("click",function(){
				alert("2");
				$(this).parent("td").parent("tr").after("<tr><td>"+i+"</td><td></td><td><a id='del'>删除此行</a>  <a id='addup'>向上添加一行</a>  <a id='adddown'>向下添加一行</a></td></tr>")
				i++;
				});
		
		});

</script>


  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值