代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="angular.min.js"></script>
<style>
tr:nth-child(2n+1){
background: palevioletred;
}
tr:nth-child(2n){
background: yellowgreen;
}
table:hover{
background: red;
}
</style>
<script>
var app= angular.module("xue",[]);
app.controller("study",function($scope){
$scope.datas=[{name:'张三',sex:'男',age:'19',birthday:new Date('1995-05-10'),address:'北京-海淀'}];
//添加
$scope.add=function(){
var name= $scope.name;
var sex= $scope.sex;
var age= $scope.age;
var birthday= $scope.birthday;
var address= $scope.address;
$scope.datas.push({name:name,sex:sex,age:age,birthday:birthday,address:address});
}
//删除
$scope.delete=function(ids){
$scope.datas.splice(ids,1);
}
//获取全选反选
$scope.qx=function(){
var f= $scope.ld;
for (var i in $scope.datas) {
$scope.datas[i].bn=f;
}
}
//批量删除
$scope.del=function(){
for (var i=0;i<$scope.datas.length;i++) {
if($scope.datas[i].bn){
$scope.datas.splice(i,1);
}
}
}
})
</script>
</head>
<body ng-app="xue" ng-controller="study">
{{datas}}
<form>
姓名:<input ng-model="name" /><br />
性别 :<input type="radio" ng-model="sex" value="男" />男
<input type="radio" ng-model="sex" value="女" />女<br />
年龄:<input ng-model="age" /><br />
生日:<input ng-model="birthday" type="date" /><br />
住址:<input ng-model="address" /><br />
<button ng-click="add()">添加</button>
<button ng-click="del()">批量删除</button>
</form>
<table align="center" border="1px">
<tr>
<th><input type="checkbox" ng-model="ld" ng-click="qx()"</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>生日</th>
<th>住址</th>
<th colspan="2">操作</th>
</tr>
<tr ng-repeat="a in datas">
<th><input type="checkbox" ng-model="a.bn"</th>
<th>{{a.name}}<input ng-model="a.name" ng-show="flag" ng-blur="flag=false"</th>
<th>{{a.sex}}</th>
<th>{{a.age}}</th>
<th>{{a.birthday}}<input ng-model="a.birthday" ng-show="flag" ng-blur="flag=false"</th>
<th>{{a.address}}</th>
<th><button ng-click="delete($index)">删除</button></th>
<th><button ng-click="flag=true">修改</button></th>
</tr>
</table>
</body>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="angular.min.js"></script>
<style>
tr:nth-child(2n+1){
background: palevioletred;
}
tr:nth-child(2n){
background: yellowgreen;
}
table:hover{
background: red;
}
</style>
<script>
var app= angular.module("xue",[]);
app.controller("study",function($scope){
$scope.datas=[{name:'张三',sex:'男',age:'19',birthday:new Date('1995-05-10'),address:'北京-海淀'}];
//添加
$scope.add=function(){
var name= $scope.name;
var sex= $scope.sex;
var age= $scope.age;
var birthday= $scope.birthday;
var address= $scope.address;
$scope.datas.push({name:name,sex:sex,age:age,birthday:birthday,address:address});
}
//删除
$scope.delete=function(ids){
$scope.datas.splice(ids,1);
}
//获取全选反选
$scope.qx=function(){
var f= $scope.ld;
for (var i in $scope.datas) {
$scope.datas[i].bn=f;
}
}
//批量删除
$scope.del=function(){
for (var i=0;i<$scope.datas.length;i++) {
if($scope.datas[i].bn){
$scope.datas.splice(i,1);
}
}
}
})
</script>
</head>
<body ng-app="xue" ng-controller="study">
{{datas}}
<form>
姓名:<input ng-model="name" /><br />
性别 :<input type="radio" ng-model="sex" value="男" />男
<input type="radio" ng-model="sex" value="女" />女<br />
年龄:<input ng-model="age" /><br />
生日:<input ng-model="birthday" type="date" /><br />
住址:<input ng-model="address" /><br />
<button ng-click="add()">添加</button>
<button ng-click="del()">批量删除</button>
</form>
<table align="center" border="1px">
<tr>
<th><input type="checkbox" ng-model="ld" ng-click="qx()"</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>生日</th>
<th>住址</th>
<th colspan="2">操作</th>
</tr>
<tr ng-repeat="a in datas">
<th><input type="checkbox" ng-model="a.bn"</th>
<th>{{a.name}}<input ng-model="a.name" ng-show="flag" ng-blur="flag=false"</th>
<th>{{a.sex}}</th>
<th>{{a.age}}</th>
<th>{{a.birthday}}<input ng-model="a.birthday" ng-show="flag" ng-blur="flag=false"</th>
<th>{{a.address}}</th>
<th><button ng-click="delete($index)">删除</button></th>
<th><button ng-click="flag=true">修改</button></th>
</tr>
</table>
</body>
</html>