<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="angular.js"></script>
<script>
var app = angular.module("myApp",[]);
app.controller("myCtrl",function ($scope) {
$scope.data = [{
key:"1",
value:"这是第一项"
},{
key:"2",
value:"这是第二项"
},{
key:"3",
value:"这是第三项"
},{
key:"4",
value:"这是第四项"
}];
$scope.arr = [];
$scope.fun = function (flag,text) {
if (flag){
$scope.arr.push(text);
}else{
for (i in $scope.arr){
if ($scope.arr[i]== text){
$scope.arr.splice(i,1);
}
}
}
}
$scope.check = function () {
if ($scope.arr.length == 0){
alert("请先选择");
}else{
alert($scope.arr);
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<button ng-click="check()">确认</button>
<ul ng-repeat="i in data">
<input type="checkbox"
name="check"
ng-value="i.key"
ng-model="flag"
ng-click="fun(flag,i.key)"
>
{{i.value}}
</ul>
</center>
</body>
</html>
选项弹值
最新推荐文章于 2017-10-25 15:48:38 发布