【发布时间】:2014-11-19 12:43:11
【问题描述】:
我正在尝试使用提交按钮取消选中复选框。这个想法是当复选框被选中时显示按钮,当按钮被点击时复选框被取消选中并且按钮被隐藏。
HTML 页面:
<html ng-app="myApp" ng-controller="myCtrl">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="script.js"></script>
<meta charset=utf-8 />
</head>
<body>
<div ng-repeat="foo in boxes">
<div>
<input type="checkbox" name="cb" id="cb" ng-model="show" />{{foo}}
</div>
<div ng-show="show">
<form ng-submit="submit()">
<input type="submit" name="sumbit" id="sumbit" value="Hide" />
</form>
</div>
</div>
</body>
</html>
JS:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.boxes = ['a','b','c'];
$scope.submit = function(){
$scope.show = false;
}
});
在 Plukner 上:http://plnkr.co/edit/z9W0w18dkgYJ3D5Q3aR2?p=preview
感谢您的帮助!
【问题讨论】:
-
您的问题到底是什么?你能解释一下你遇到问题的地方吗?你有错误吗?有什么事吗?
-
如何取消选中带有提交按钮的复选框?我在提交函数中将 show 设置为 false,但 ng-model 无法识别 show 为 false 以取消选中复选框。我是在正确的道路上,还是以其他方式运作?