<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/anglarjs.min.js"></script>
<script src="js/jquery-1.11.1.js"></script>
<script>
var z_app = angular.module("APP", []);
z_app.controller("dex", ["$scope", function($scope) {
$scope.users = [{
name: "adw",
age: 15
}, {
name: "adw",
age: 15
}, {
name: "adw",
age: 15
}, {
name: "adw",
age: 15
}, {
name: "adw",
age: 15
}];
$scope.remove = function(a) {
$scope.users.splice(a, 1);
}
$scope.add = function() {
var aname = $scope.uname;
var age = $scope.uage;
if(aname == ""||aname==undefined) {
$("#uu_name").text("不能为空");
$("#uu_name").css("color", "red");
return;
} else {
$("#uu_name").text("");
}
$scope.users.push({
name: aname,
age: age
});
$scope.toadd = false;
}
}])
</script>
<style>
div {
width: 300px;
background-color: darkgrey;
}
</style>
</head>
<body ng-app="APP" ng-controller="dex">
<table width="400px" border="1px">
<tr ng-repeat="u in users" ng-init="xianshi=true">
<td width="100px"> <span ng-show="xianshi" >{{u.name}}</span>
<input type="text" ng-model="u.name" ng-show="!xianshi" />
</td>
<td width="100px">{{u.age}}</td>
<td width="100px"> <input type="button" value="删除 " ng-click="remove($index)" /> ||
<input type="button" value="修改" ng-click="xianshi=false" ng-show="xianshi"/>
<input type="button" value="保存" ng-click="xianshi=true" ng-show="!xianshi" />
</td>
</tr>
</table>
<input type="button" value="添加" ng-click="toadd=true" />
<form ng-show="toadd">
姓名:<input type="text" ng-model="uname" />
<span id="uu_name"></span>
<br /> 年龄:
<input type="text" ng-model="uage" /><br />
<input type="button" value="queding" ng-click="add()" />
</form>
</body>
</html>