输入字段不会清除

ham

即使按照教程的步骤操作,我也无法清除输入字段,我将其列为待办事项,并且希望在我提交新内容时清除输入字段。那么我的代码有什么问题呢?ps:我试图清除缓存,什么也没有

let addButton=document.getElementById('addButton');
let toDoContainer = document.getElementById('ToDoContainer');
let inputField = document.getElementById('text');
//event listeners 
addButton.addEventListener('click',addTodo);


//functions 
function addTodo(event,title){
    event.preventDefault();
    //create the to do 
    let toDoDiv = document.createElement('div');
    toDoDiv.classList.add('todo');
    const newToDo =document.createElement('p');
    newToDo.innerHTML=inputField.value;
    newToDo.classList.add('todo-item');
    toDoDiv.appendChild(newToDo);
    toDoContainer.appendChild(toDoDiv);
    //check mark button 
    const completedButton = document.createElement('button');
    completedButton.innerHTML="success";
    completedButton.classList.add("complete-btn");
    toDoDiv.appendChild(completedButton);
    //check delete button 
    const trashButton = document.createElement('button');
    trashButton.innerHTML="delete";
    trashButton.classList.add("complete-btn");
    toDoDiv.appendChild(trashButton);
    //append todo 
    toDoContainer.appendChild(tododiv);
    inputField.value= "";
    
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>to do list </title>
    <link rel="stylesheet" href="./style.css">
    
</head>

<body>

    <div class="container">
        <header>
            <h1>This is your to do list </h1>
            <div class="input">
                <input type="text" placeholder="what to do ...?" id="text">
                <input type="button" value="add" id="addButton">
            </div>
        </header>


        <div id="ToDoContainer">
                
                    
        </div>


    </div>
    <script src="./script.js"></script>
</body>

</html>

这是截图

米歇尔·帕拉迪斯(Michelle Paradis)

sonEtLumiere是对的,您有错字。它应该是:

toDoContainer.appendChild(toDoDiv);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

清除预先输入字段

来自分类Dev

CasperJS清除输入字段

来自分类Dev

使用Reactjs清除输入字段?

来自分类Dev

按Enter清除输入字段

来自分类Dev

输入字段清除后消失

来自分类Dev

按Enter清除输入字段

来自分类Dev

如何清除TextInputDialog的输入字段?

来自分类Dev

提交时清除输入字段

来自分类Dev

单击按钮清除输入字段

来自分类Dev

输入字段的宽度不会减少

来自分类Dev

清除Bootstrap中的表单输入字段?

来自分类Dev

选择预输入后如何清除字段?

来自分类Dev

清除Angular表单提交中的输入字段?

来自分类Dev

如何清除Validator类中的输入字段?

来自分类Dev

如何清除AngularJS中的输入字段

来自分类Dev

单击按钮时清除输入字段

来自分类Dev

如何清除jQuery中的特定输入字段

来自分类Dev

从页脚中清除Kendo Datepicker输入字段

来自分类Dev

使用React钩子清除输入字段

来自分类Dev

如何使用jQuery清除输入字段值?

来自分类Dev

关闭时清除表单输入字段

来自分类Dev

如何清除图像的单击输入字段?

来自分类Dev

清除输入字段,但“提交”按钮除外

来自分类Dev

如何清除Angular中过滤的输入字段?

来自分类Dev

如何清除AngularJS中的输入字段

来自分类Dev

清除字段并在DalekJS中输入

来自分类Dev

清除嵌套指令中的无效输入字段

来自分类Dev

如何清除Bootstrap DateRangePicker字段的输入

来自分类Dev

单击按钮后清除输入字段