jQuery--员工管理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tyutjavalily/article/details/47665257
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">

	$(function(){
		//删除a节点所在的tr节点,使用remove()方法
		function removeTr(aNode){
			
			var $aTr=$(aNode).parent().parent();//返回的是jQuery对象
			var textContent=$aTr.find("td:first").text();
			textContent=$.trim(textContent);
			var flag=confirm("确定要删除"+textContent+"吗?");
			if(flag){
				$aTr.remove();
			}
			return false;
		}
		
		//给a节点添加点击事件
		$("#employeetable a").click(function(){
			return removeTr(this); 	
		});
		
		//给#addEmpButton添加响应事件
		$("#addEmpButton").click(function(){
			
			$("<tr></tr>").append($("<td>" +$("#name").val()+ "</td>"))
						  .append($("<td>" +$("#email").val()+ "</td>"))
						  .append($("<td>" +$("#salary").val()+ "</td>"))
						  .append($("<td><a href='deleteEmp?id=xxx'>Delete</a></td>"))
						  .appendTo($("#employeetable tbody"))
						  .find("a")
						  	.click(function(){
						  		
						  		return removeTr(this);
						  	});
		});
	})
	

</script>
</head>
<body>

	<center>
		<br> <br> 添加新员工 <br> <br> name: <input type="text"
			name="name" id="name" />   email: <input type="text"
			name="email" id="email" />   salary: <input type="text"
			name="salary" id="salary" /> <br> <br>
		<button id="addEmpButton" value="abc">Submit</button>
		<br> <br>
		<hr>
		<br> <br>
		<table id="employeetable" border="1" cellpadding="5" cellspacing=0>
			<tbody>
				<tr >
					<th>Name</th>
					<th>Email</th>
					<th>Salary</th>
					<th> </th>
				</tr>
				<tr value="1">
					<td>Tom</td>
					<td>tom@tom.com</td>
					<td>5000</td>
					<td><a href="deleteEmp?id=001">Delete</a></td>
				</tr>
				<tr>
					<td>
						Jerry
					</td>
					<td>jerry@sohu.com</td>
					<td>8000</td>
					<td><a href="deleteEmp?id=002">Delete</a></td>
				</tr>
				<tr>
					<td>Bob</td>
					<td>bob@tom.com</td>
					<td>10000</td>
					<td><a href="deleteEmp?id=003">Delete</a></td>
				</tr>
			</tbody>
		</table>
	</center>

</body>
</html>

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页