用HTML写一个移动端简易日记本app
时间: 2023-05-23 11:04:42 浏览: 49
A:
<!DOCTYPE html>
<html>
<head>
<title>移动端简易日记本App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
.header {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
}
.container {
padding: 10px;
}
textarea {
width: 100%;
height: 200px;
margin-bottom: 10px;
padding: 5px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
resize: none;
}
.button {
background-color: #4CAF50;
border: none;
color: #fff;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-bottom: 10px;
cursor: pointer;
border-radius: 5px;
}
.button:hover {
background-color: #3e8e41;
}
.note {
background-color: #fff;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}
.note h2 {
margin-top: 0;
}
.note p {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="header">
<h1>移动端简易日记本App</h1>
</div>
<div class="container">
<form id="note-form">
<label for="note">添加新的日记:</label>
<textarea id="note" placeholder="在这里输入日记内容"></textarea>
<button class="button" type="submit">添加日记</button>
</form>
<div id="notes"></div>
</div>
<script>
const form = document.getElementById('note-form');
const notes = document.getElementById('notes');
form.addEventListener('submit', addNote);
function addNote (event) {
event.preventDefault();
const textarea = document.getElementById('note');
const noteText = textarea.value.trim();
if (noteText !== '') {
const note = document.createElement('div');
note.classList.add('note');
note.innerHTML = `
<h2>今天</h2>
<p>${noteText}</p>
`;
notes.insertBefore(note, notes.firstChild);
textarea.value = '';
}
}
</script>
</body>
</html>