JSFiddle - React, Tailwind, and code Playground
by johnny890118
HTML
<body>
<div class="top">
<h1>
待辦事項管理
</h1>
<br>
<input id="text" type="text" placeholder="請輸入待辦事項">
<button id="enter" onclick="myfunction()">
新增
</button>
<br>
</div>
<div class="content">
<div class="center">
<ul id="app">
</ul>
</div>
</div>
</body>
CSS
* {
margin: 0px;
padding: 0px;
}
.top {
background-color: #F8F4EA;
text-align: center;
padding: 20px;
}
.top h1 {
color: #579BB1;
}
#enter {
background-color: #579BB1;
color: white;
height: 40px;
width: 60px;
border: hidden;
}
#enter:hover {
background-color: #437d90;
}
#text {
height: 40px;
border: hidden;
width: 500px;
}
body {
background-color: #ECE8DD;
}
.content {
display: flex;
justify-content: center;
}
.center {
width: 400px;
margin-top: 30px;
}
#app {
list-style-type: none;
}
#app li {
height: 30px;
font-size: 20px;
background-color: #E1D7C6;
padding: 5px;
margin: 5px;
border-radius: 5px;
}
#app input{
margin: 5px;
}
JavaScript
function myfunction() {
var text = document.getElementById("text").value;
var app = document.getElementById("app");
var li = document.createElement("li");
var span = document.createElement("span");
var span1 = document.createElement("span");
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
span.textContent = text;
app.append(li);
li.append(span1,span);
span1.append(checkbox);
}