JSFiddle - React, Tailwind, and code Playground

by johnny890118

HTML

<body>
  <div class="top">
    <h1>
      待辦事項管理
    </h1>
    <br>
    <div class="entergroup">
      <input id="text" type="text" placeholder="請輸入待辦事項">
      <button id="enter" onclick="myfunction()">
        +
      </button>
    </div>
  </div>
  <div class="content">
    <div class="center">
      <ul id="app">
      </ul>
    </div>
  </div>
  <div class="exportdiv">
    <button id="export" onclick = "myfunction3()">
      匯出為純文字
    </button>
  </div>
</body>

CSS

* {
  margin: 0px;
  padding: 0px;
}

.top {
  background-color: #F8F4EA;
  text-align: center;
  padding: 20px;
}

.top h1 {
  color: #579BB1;
}

.entergroup {
  display: flex;
  justify-content: center;
}

#enter {
  background-color: #579BB1;
  color: white;
  height: 40px;
  width: 60px;
  border: hidden;
  font-size: 25px;
}

#enter:hover {
  background-color: #437d90;
}

#text {
  height: 40px;
  border: hidden;
  width: 400px;
}

body {
  background-color: #ECE8DD;
}

.content {
  display: flex;
  justify-content: center;
  padding-bottom: 30px;
}

.center {
  width: 400px;
  margin-top: 30px;
}

#app {
  list-style-type: none;
}

#app li {
  height: 30px;
  font-size: 20px;
  background-color: #E1D7C6;
  padding: 5px 15px;
  margin: 5px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#app button {
  color: #F8F4EA;
  background-color: #E1D7C6;
  border: hidden;
  font-size: 20px;
}

#app button:hover {
  color: red;
}

.exportdiv {
  display: flex;
  justify-content: center;
}

#export {
  background-color: #579BB1;
  color: white;
  margin-bottom: 30px;
  height: 40px;
  width: 100px;
  border: hidden;

}

#export:hover {
  background-color: #437d90;
}

JavaScript

function myfunction() {
  function myfunction2() {
    li.remove();
  }
  var text = document.getElementById("text").value;
  var app = document.getElementById("app");
  var li = document.createElement("li");
  var span = document.createElement("span");
  var btn = document.createElement("button");
  span.textContent = text;
  btn.textContent = "X";
  app.append(li);
  li.append(span);
  li.append(btn);
  btn.onclick = myfunction2;
}

function myfunction3() {
  var app1 = document.getElementById("app").children;
  var num = 1;
  var output = "";
  for (var y of app1) {
    output = output + "  "+num.toString() + ". " + y.children[0].textContent;
    num = num + 1;
  }
  alert("今日待辦: " + output);
}