-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q4.html
76 lines (63 loc) · 1.91 KB
/
Q4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html>
<head>
<title>實作:To-Do List(Q4:變色)</title>
<style>
div{
margin-top: 50px;
text-align: center;
}
</style>
<script>
"use strict";
function createToDo(){
//to do html標籤
var todo = document.createElement("div");
var span = document.createElement("span");
// 新建 to do 功能
var input = document.getElementById("input").value;
if (input == ""){
input = "沒指定工作";
}
span.innerHTML = input;
todo.appendChild(span);
//replace 按鈕設計
var replaceButton = document.createElement("button");
replaceButton.onclick = function(){
var input = document.getElementById("input").value;
if (input == ""){
alert("不能空白");
return;
}
this.parentNode.firstChild.innerHTML = input;
document.getElementById("input").value = "";
}
replaceButton.textContent = "R";
todo.appendChild(replaceButton);
//remove 按鈕設計
var removeButton = document.createElement("button");
removeButton.onclick = function(){
var answer = confirm("是否已完成?");
if (answer == true){
this.parentNode.style.color = "blue";
this.parentNode.removeChild(replaceButton);
this.parentNode.removeChild(this);
}
}
removeButton.textContent = "V";
todo.appendChild(removeButton);
//所有按鈕與功能加入 todolist
document.getElementById("todolist").appendChild(todo);
document.getElementById("input").value = "";
}
</script>
</head>
<body>
<div>
<h1>To Do List</h1>
<input type="text" id="input">
<button onclick="createToDo()"> + </button>
<div id="todolist">
</div>
</div>
</body>
</html>