按鈕,選擇選擇複選框,按鈕將選擇取消 - 取消選擇它:
<!doctype html>
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Angular Ajax with PHP</title>
</head>
<body>
<h2>The form</h2>
<div ng-app="myApp" ng-controller="mainController">
<input type="checkbox" ng-model="value.selected"/>
<p>{{value.selected}}</p>
<button ng-click="select()">Select</button>
<button ng-click="deselect()">Deselect</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller('mainController',function($scope){
$scope.value = {
selected:false
};
$scope.select = function(){
$scope.value.selected = true;
}
$scope.deselect = function() {
$scope.value.selected = false;
}
});
</script>
</body>
</html>
我已經試過這個方法了。當我在Plunker中嘗試你的代碼時,它工作正常,但是當我嘗試在代碼中複製代碼時,它不會更改DOM中的任何內容,但該模型仍然會更改其值。 –
你能顯示你的完整代碼嗎? –