记事小本本

记事小本本

实现效果

相关代码

javascript 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
            box-sizing: border-box;
        }
        .nav {
            width: 800px;
            height: 100px;
            margin: 0 auto;
            display: flex;
            align-items: center;
            border-radius: 5px;
        }
        .nav input {
            width: 600px;
            height: 60px;
        }
        .nav button {
            width: 200px;
            height: 60px;
            background-color: orange;
            color: white;
            font-size: 20px;
            border: orange;
            border-radius: 5px;

        }
        .container {
            width: 800px;
            display: flex;
            margin: 0px auto;
        }
        h3 {
            background-color: gray;
            color: white;
            text-align: center;
            width: 400px;
            height: 60px;
            padding-top: 15px;
        }
        
        .todo, .done {
            width: 50%;
            height: 100%;
        }
        .row {
            width: 400px;
            display: flex;
            align-items: center;
            margin-top: 10px ;

        }
        span {
            width: 200px;
            height: 40px;
            font-size: 20px;
            margin-left: 5px;
            margin-top: 15px;
        }
        .row button {
            width: 90px;
            height: 40px;
            font-size: 20px;
            margin-top: 10px;
        }
        .nav button:active {
            background-color: grey;
        }
       
        input[type="checkbox"] {
            width: 20px;
            height: 20px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div class="nav">
        <input type="text"><button onclick="newJob()">新建任务</button>
    </div>
    <div class="container">
        <div class="todo">
            <h3>未完成</h3>
        </div>
        <div class="done">
            <h3>已完成</h3>
        </div>
    </div>
</body>
<script>
    function newJob() {
        let input = document.querySelector('.nav input')
        let input_info = input.value
        if(input_info == '') {
            return
        }
        let todo = document.querySelector('.todo')
        let div = document.createElement('div')
        let checkbox = document.createElement('input')
        checkbox.type = "checkbox"
        let span = document.createElement('span')
        span.innerHTML = input_info
        let button = document.createElement('button')
        button.innerHTML = "删除"
        div.appendChild(checkbox)
        div.appendChild(span)
        div.appendChild(button)
        div.className = 'row'
        todo.appendChild(div)
        let delete_buttons = document.querySelectorAll('.row button')
        for(i = 0; i < delete_buttons.length; i++) {
            delete_buttons[i].onclick = function() {
                let parent = this.parentNode;
                let grand_parent = parent.parentNode
                grand_parent.removeChild(parent)
            }
        }
        let checkbox_buttons = document.querySelectorAll('.row input')
        for(i = 0; i < checkbox_buttons.length; i++) {
            checkbox_buttons[i].onclick = function() {
                let row = this.parentNode;
                let targrt;
                if(this.checked) {
                    targrt = document.querySelector('.done')
                }else {
                    targrt = document.querySelector('.todo')
                }
                targrt.appendChild(row)
            }
        }
        input.value = ""
    }
</script>
</html>
相关推荐
lbh21 小时前
当我开始像写代码一样和AI对话,一切都变了
前端·openai·ai编程
We་ct1 天前
LeetCode 918. 环形子数组的最大和:两种解法详解
前端·数据结构·算法·leetcode·typescript·动态规划·取反
qq_406176141 天前
深入浅出 Pinia:Vue3 时代的状态管理新选择
javascript·vue.js·ecmascript
wefly20171 天前
m3u8live.cn 在线M3U8播放器,免安装高效验流排错
前端·后端·python·音视频·前端开发工具
C澒1 天前
微前端容器标准化 —— 公共能力篇:通用打印
前端·架构
德育处主任Pro1 天前
前端元素转图片,dom-to-image-more入门教程
前端·javascript·vue.js
木斯佳1 天前
前端八股文面经大全:小红书前端一二面OC(下)·(2026-03-17)·面经深度解析
前端·vue3·proxy·八股·响应式
陈天伟教授1 天前
人工智能应用- 预测新冠病毒传染性:04. 中国:强力措施遏制疫情
前端·人工智能·安全·xss·csrf
叫我一声阿雷吧1 天前
JS 入门通关手册(23):JS 异步编程:回调函数与异步本质
javascript·es6·前端面试·回调函数·回调地狱·js异步编程·异步本质
zayzy1 天前
前端八股总结
开发语言·前端·javascript