zoukankan      html  css  js  c++  java
  • jquery动态加入删除一行数据

    <html>
    <head>
    <title>加入、删除一行</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
    <script type="text/javascript">
    	$(function() {
    		$("#addOneRow").click(function() {
    			var tempTr = $("tr:first").clone(true);
    			$("tr:last").after(tempTr);
    			$("tr:last > td > #name").val("");//新加入行name为空
    			$("tr:last > td > #address").val("");//新加入行address为空
    		});
    		$(".delOneRow").click(function() {
    			if ($("tr").length < 2) {
    				alert("至少保留一行!");
    			} else {
    				if (confirm("确认删除?")) {
    					// $(this).parent().parent().remove();
    					$(this).parents("tr").remove();
    				}
    			}
    		});
    	});
    </script>
    </head>
    
    <body>
    	<table border="1">
    		<tr>
    			<td>姓名:</td>
    			<td><input type="text" id="name" name="name" />
    			</td>
    			<td>地址:</td>
    			<td><input type="text" id="address" name="address" /></td>
    			<td><input type="button" class="delOneRow" value="删除" /></td>
    		</tr>
    	</table>
    	<input type="button" id="addOneRow" value="加入一行" />
    </body>
    
    </html>


  • 相关阅读:
    【YbtOJ#911】欧拉函数
    【CF590E】Birthday
    打印控件的区别
    RPA教程
    UiPath培训教程
    RPA视频教程
    搭建samba服务
    kvm虚拟机在线扩容
    zabbix监控交换机
    UiPath Level3讲解
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/3965889.html
Copyright © 2011-2022 走看看