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="請輸入待辦事項">
      <select id="choose" onchange="myfunction4()">
        <option value="normal">一般</option>
        <option value="important">重要</option>
        <option value="warn">緊急</option>
      </select>
      <button id="enter" class="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;
  border-radius: 0px 10px 10px 0px;
}

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

#text {
  height: 40px;
  border: hidden;
  width: 400px;
  border-radius: 10px 0px 0px 10px;
}

#choose {
  border: hidden;
}

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;
  border-radius: 5px;

}

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

.important {
  color: #fc9303;
}

.warn {
  color: red;
}

.btnimportant{
  background-color: #fc9303;
  color: white;
  height: 40px;
  width: 60px;
  border: hidden;
  font-size: 25px;
  border-radius: 0px 10px 10px 0px;
}

.btnwarn{
  background-color: red;
  color: white;
  height: 40px;
  width: 60px;
  border: hidden;
  font-size: 25px;
  border-radius: 0px 10px 10px 0px;
}

.btnnormal {
  background-color: #579BB1;
  color: white;
  height: 40px;
  width: 60px;
  border: hidden;
  font-size: 25px;
  border-radius: 0px 10px 10px 0px;
}

JavaScript

function myfunction4() {
   let choose = document.getElementById("choose").value;
   let btn2 = document.getElementById("enter");
   btn2.className = "btn" + choose;
 }

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

 function myfunction3() {
   let app1 = document.getElementById("app").children;
   let num = 1;
   let output = "";
   for (let y of app1) {
     let yclass = y.children[0].className;
     if (yclass == "important") {
       output = output + "  " + num.toString() + ". " + "*" + y.children[0].textContent + "*";
     } else if (yclass == "warn") {
       output = output + "  " + num.toString() + ". " + "**" + y.children[0].textContent + "**";
     } else {
       output = output + "  " + num.toString() + ". " + y.children[0].textContent;
     }
     num = num + 1;
   }
   alert("今日待辦: " + output);
 }