1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

簡単なTodoアプリ作ってみた-勉強のメモ

Posted at

簡単(すぎる)Todoアプリの作成過程をまとめて。

#目的
簡単なTodoアプリを作る

#コード

HTML
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
    <link href="https://fonts.googleapis.com/css?family=M+PLUS+Rounded+1c&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
    <title>Todo App</title>
</head>
<body>

    <section>

        <h1>Todo List</h1>

        <div class="todo_add">
            <div id="add_btn"><i class="fas fa-plus"></i></div>
            <input type="text" id="input_add" placeholder="追加する">
        </div>

        <ul id="list_todo"></ul>

    </section>
    
</body>
</html>
CSS
body{
    font-family: 'M PLUS Rounded 1c', sans-serif;
}

h1{
    text-align: center;
    border-bottom: 3px solid #38b1f7;
    color: #38b1f7;
    font-size: 40px;
    letter-spacing: 10px;
    padding-bottom: 25px;
    
}

.todo_add{
    display: flex;
    margin-left: 500px;
}

#add_btn{
    background-color: #38b1f7;
    border-radius: 40px;
    width: 40px;
    height: 40px;
    color: #ffffff;
    font-size: 20px;
    text-align: center;
    line-height: 40px;
   margin-right: 20px;

}

#input_add{
    border-radius: 10px;
    border: 1px solid #6b635a;
    width: 240px;

}

.todo_li{
    
    font-size: 20px;
    padding: 10px 0;

}
JavaScript

const add = document.getElementById('add_btn');

    add.addEventListener("click", function() {

      const li = document.createElement('li');

      document.getElementById('list_todo').appendChild(li);

      li.classList.add('todo_li');

      li.textContent = `${input_add.value}`;

    })

#コードの解説

<ul id="list_todo"></ul>

JavaScript
const li = document.createElement('li');

document.getElementById('list_todo').appendChild(li);

list_tododocument.createElementliを生成する。

JavaScript
li.classList.add('todo_li');

classListで生成したliにクラスを追加する。

JavaScript
li.textContent = `${input_add.value}`;

textContentvalueで入力された文字をtodo_liに表示する。

#感想
(あまりにも物足りなさすぎるので削除機能とかタスクをジャンルごとに分ける機能とかつけたい…)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?