-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled-1.html
More file actions
100 lines (86 loc) · 2.78 KB
/
Untitled-1.html
File metadata and controls
100 lines (86 loc) · 2.78 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html>
<head>
<title>表白墙</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #f2f2f2;
padding: 20px;
text-align: center;
}
h1 {
color: #333;
}
main {
width: 80%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.confession {
margin-bottom: 20px;
padding: 20px;
background-color: #f9f9f9;
border-radius: 5px;
}
.confession h3 {
color: #333;
}
.confession p {
color: #666;
}
</style>
</head>
<body>
<header>
<h1>表白墙</h1>
</header>
<main>
<section>
<h2>我的表白</h2>
<form id="confessionForm">
<input type="text" id="titleInput" placeholder="请输入表白标题">
<textarea id="contentInput" placeholder="请输入表白内容"></textarea>
<button type="submit">提交</button>
</form>
</section>
<section>
<h2>表白列表</h2>
<div id="confessionList">
<!-- 表白列表将通过JavaScript动态添加 -->
</div>
</section>
</main>
<footer>
© 2023 表白墙。保留所有权利。
</footer>
<script>
// 提交表白内容
document.getElementById("confessionForm").addEventListener("submit", function(event) {
event.preventDefault(); // 阻止表单默认提交行为
// 获取表单输入值
var title = document.getElementById("titleInput").value;
var content = document.getElementById("contentInput").value;
// 创建表白内容节点
var confessionNode = document.createElement("div");
confessionNode.className = "confession";
confessionNode.innerHTML = `
<h3>${title}</h3>
<p>${content}</p>
<p>时间:${new Date().toLocaleString()}</p>
`;
// 将表白内容节点添加到列表中
var confessionList = document.getElementById("confessionList");
confessionList.prepend(confessionNode);
// 清空表单输入
document.getElementById("titleInput").value = "";
document.getElementById("contentInput").value = "";
});
</script>
</body>
</html>