Angularjs添加用户

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>添加元素</title>
		<script type="text/javascript" src="js/angular.js" ></script>
		<script type="text/javascript" src="js/angular-route.js" ></script>
		<style>
			button{
				border: 5px solid blue;
				background-color: blue;
				border-radius: 5%;
			}
		</style>
		<script>
			var app = angular.module("myApp",[]);
			app.controller("myCtrl",function($scope){
				$scope.users = [
				{name:"张三",sex:"男",age:"15",work:"teacher"},
				{name:"张四",sex:"女",age:"16",work:"worker"},
				{name:"王五",sex:"男",age:"17",work:"chair"}];
				
				 $scope.name = "";
				 $scope.sex = "";
				 $scope.age = "";
				 $scope.work = "";
				   
					
				$scope.addel = function(){
					
					var newUsers = {
						name:$scope.name,
						sex:$scope.sex,
						age:$scope.age,
						work:$scope.work};
					$scope.users.push(newUsers)
					
				}
				
				
			});
		</script>
	</head>
	<body ng-app="myApp" ng-controller="myCtrl">
		<center>
		<caption><h3>学生信息表</h3></caption><br />
		<table border="2" cellpadding="10" cellspacing="0" width="500px" style="text-align: center;">
			<thead>
				<tr>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>职业</th>
				</tr>
			</thead>
			<tbody>
				<tr ng-repeat="user in users">
					<td>{{user.name}}</td>
					<td>{{user.sex}}</td>
					<td>{{user.age}}</td>
					<td>{{user.work}}</td>
				</tr>
			</tbody>
		</table><br />
		
		<div>
			姓名:<input type="text" ng-model="name"><br/><br />
			性别:<input type="text" ng-model="sex"><br/><br />
			年龄:<input type="text" ng-model="age"><br/><br />
			职业:<input type="text" ng-model="work">
		</div>
		<button ng-click="addel()">增加用户</button>
		</center>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值