代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html ng-app="todo">
<head>
<title>TodoList</title>
<script src="../angular.min.js"></script>
<script type="text/javascript">
var todoModule=angular.module('todo',[]);
todoModule.controller('cc',function($scope){
$scope.input={title:'',fulfil:false};
$scope.editOrAdd = "Add";
$scope.currIndex=0;
$scope.todos=[
{fulfil:true,title:'test1'},
{fulfil:false,title:'test2'},
{fulfil:false,title:'test3'}
];
$scope.add=function(){
if($scope.input.title.length==0){
return;
}
if($scope.editOrAdd == "Modify"){
if($scope.currIndex < 0){
alert("currIndex less zero.")
return;
}
index=$scope.currIndex;
$scope.todos[index]={title:$scope.input.title,fulfil:$scope.input.fulfil};
$scope.input={title:'',fulfil:false};
$scope.editOrAdd = "Add";
$scope.currIndex= -1 ;
}else if($scope.editOrAdd == "Add"){
var title=$scope.input.title;
$scope.todos.push({title:title,fulfil:false});
$scope.input.title='';
}
}
$scope.remove=function(index){
$scope.todos.splice(index,1);
}
$scope.modify=function(index){
$scope.input=$scope.todos[index];
$scope.editOrAdd="Modify";
$scope.currIndex=index;
}
})
</script>
<style type="text/css">
.fulfil{
color:gray;
text-decoration: line-through;
}
</style>
</head>
<body >
<div ng-controller='cc'>
<h1>TODO:</h1>
<input ng-model="input.title">
<button ng-click='add()'>{{editOrAdd}}</button>
<div ng-repeat='todo in todos'>
<input type="checkbox" ng-model='todo.fulfil' >
<span ng-class={fulfil:todo.fulfil} ng-dblclick='modify($index)'>{{todo.title}}</span>
<button ng-click='remove($index)'>Delete</button>
</div>
</div>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。