使用JavaScript制作待办事项列表

这是一个使用HTML、CSS和JavaScript实现的待办事项清单应用程序。用户可以输入任务,点击添加按钮将任务添加到清单中,每个任务都可以删除。页面具有响应式设计,简洁的用户界面,并集成了百度统计代码。
摘要由CSDN通过智能技术生成

效果图:

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bGx5pyI5Ymn,size_20,color_FFFFFF,t_70,g_se,x_16

 项目源码如下:

<!DOCTYPE html>
<html>
<head>
    <title>待办事项清单</title>
    <style media="screen">
        *,
        *:before,
        *:after {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        body {
            height: 100vh;
            background: #066acd;
        }

        .container {
            width: 40%;
            min-width: 450px;
            position: absolute;
            transform: translate(-50%, -50%);
            top: 50%;
            left: 50%;
            background: white;
            border-radius: 10px;

        }

        #newtask {
            position: relative;
            padding: 30px 20px;
        }

        #newtask input {
            width: 75%;
            height: 45px;
            font-family: 'Poppins', sans-serif;
            font-size: 15px;
            border: 2px solid #d1d3d4;
            padding: 12px;
            color: #111111;
            font-weight: 500;
            position: relative;
            border-radius: 5px;
        }

        #newtask input:focus {
            outline: none;
            border-color: #0d75ec;
        }

        #newtask button {
            position: relative;
            float: right;
            width: 20%;
            height: 45px;
            border-radius: 5px;
            font-family: 'Poppins', sans-serif;
            font-weight: 500;
            font-size: 16px;
            background-color: #0d75ec;
            border: none;
            color: #ffffff;
            cursor: pointer;
            outline: none;
        }

        #tasks {
            background-color: #ffffff;
            padding: 30px 20px;
            margin-top: 10px;
            border-radius: 10px;
            width: 100%;
            position: relative;
        }

        .task {
            background-color: #c5e1e6;
            height: 50px;
            margin-bottom: 8px;
            padding: 5px 10px;
            display: flex;
            border-radius: 5px;
            align-items: center;
            justify-content: space-between;
            border: 1px solid #939697;
            cursor: pointer;
        }

        .task span {
            font-family: 'Poppins', sans-serif;
            font-size: 15px;
            font-weight: 400;
        }

        .task button {
            background-color: #0a2ea4;
            color: #ffffff;
            height: 100%;
            width: 40px;
            border-radius: 5px;
            border: none;
            cursor: pointer;
            outline: none;
        }

        .completed {
            text-decoration: line-through;
        }
    </style>
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?a9430a37066911650e26adadcc42798a";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>
<body>
<div class="container">
    <div id="newtask">
        <input type="text" placeholder="要完成的任务..">
        <button id="push">添加</button>
    </div>

    <div id="tasks"></div>
</div>
<!--Script-->
<script type="text/javascript">
    document.querySelector('#push').onclick = function () {
        if (document.querySelector('#newtask input').value.length == 0) {
            alert("请输入任务")
        } else {
            document.querySelector('#tasks').innerHTML += `
            <div class="task">
                <span id="taskname">
                    ${document.querySelector('#newtask input').value}
                </span>
                <button class="delete">
                    <i class="far fa-trash-alt"></i>
                </button>
            </div>
        `;

            var current_tasks = document.querySelectorAll(".delete");
            for (var i = 0; i < current_tasks.length; i++) {
                current_tasks[i].onclick = function () {
                    this.parentNode.remove();
                }
            }
        }
    }
</script>
</body>
</html>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈老说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值