-
Notifications
You must be signed in to change notification settings - Fork 26
/
index8.js
71 lines (55 loc) · 1.36 KB
/
index8.js
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
const content = document.getElementById('content')
const date = document.getElementById('date')
const time = document.getElementById('time')
const addedBtn = document.getElementById('addedBtn')
const deletedBtn = document.getElementById('deletedBtn')
const list = document.getElementById('list')
const listContent = []
// class RenderFeature{
// append() {
// }
// render() {
// // 渲染頁面的list
// let htmlStr = ''
// listContent.forEach(function (item) {
// htmlStr = htmlStr + `
// <div class="item">
// <div>
// <p>內容:${item.content}</p>
// <p>時間:${item.date} ${item.time}</p>
// </div>
// </div>
// `
// })
// list.innerHTML = htmlStr
// }
// }
// function
function render() {
// 渲染頁面的list
let htmlStr = ''
listContent.forEach(function (item) {
htmlStr = htmlStr + `
<div class="item">
<div>
<p>內容:${item.content}</p>
<p>時間:${item.date} ${item.time}</p>
</div>
</div>
`
})
list.innerHTML = htmlStr
}
// const r1 = new RenderFeature()
addedBtn.addEventListener('click', function () {
listContent.unshift({
content: content.value,
date: date.value,
time: time.value
})
render()
})
deletedBtn.addEventListener('click', function () {
listContent.shift()
render()
})