以下是创建待办事项列表的代码 -
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script xx_src="https://code.jquery.com/jquery-1.12.4.js"></script> <script xx_src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <input type="text" placeholder="请在此处输入您的任务.." id="txtData"> <button onclick="todoList()">AddTaskToDo</button> <ul id="to_do_list"> </ul> </body> <script> function todoList() { const myTask = document.getElementById('txtData'); const addToDoList = document.getElementById('to_do_list'); let originalValue = `<li> ${myTask.value} </li>`; myTask.value= ''; addToDoList.insertAdjacentHTML('beforeend', originalValue); } </script> </html>
要运行上述程序,请保存文件名“anyName.html(index.html)”。右键单击文件并在 VSCode 编辑器中选择“使用 Live Server 打开”选项 -
这将产生以下输出 -
现在在这里,我将进入第一个任务。
进入第一个任务后,点击按钮。
输出结果
这将在控制台上产生以下输出 -
再次,我正在输入另一项任务。
单击按钮后,您将获得以下输出 -