我是一名初學者,想用一些JavaScript來學習/理解它在做什麼。我在AngularJS網站上發現了這個基本的「待辦事項列表」腳本,並開始玩弄它。當您選中複選框時,我添加了一個msg,但是當我取消選中它時,我收到了同樣的msg。因此,最好的選擇是在檢查時無法取消選中它。我尋找了相當一段時間,但找不到正確的答案。也許你們有些人知道該怎麼做?禁用在AngularJS中選中複選框時取消選中
在此先感謝!
這裏是我的代碼 HTML:
<div ng-controller="TodoListController as todoList">
<span>Nog {{todoList.remaining()}} van de {{todoList.todos.length}} te gaan!</span>
<!--[ <a href="" ng-click="todoList.archive()">archive</a> ]-->
<ul class="unstyled">
<li ng-repeat="todo in todoList.todos">
<label class="checkbox">
<input type="checkbox" onclick="alert('Well done!')" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</label>
</li>
</ul>
</div> <!--einde ng-controller -->
AngularJS
angular.module('todoApp', [])
.controller('TodoListController', function() {
var todoList = this;
todoList.todos = [
{text:'Leer HTML5', done:true},
{text:'Leer CSS3', done:true},
{text:'Leer Javascript', done:false},
];
todoList.remaining = function() {
var count = 0;
angular.forEach(todoList.todos, function(todo) {
count += todo.done ? 0 : 1;
});
return count;
};
todoList.archive = function() {
var oldTodos = todoList.todos;
todoList.todos = [];
angular.forEach(oldTodos, function(todo) {
if (!todo.done) todoList.todos.push(todo);
});
};
});
所以,你想,當它被選中禁用複選框? –
是的,這就是我想要達到的。 –
嘗試更改 –