gpt4 book ai didi

javascript - 获取 INVALID_CHARACTER_ERR : DOM Exception 5

转载 作者:行者123 更新时间:2023-11-29 18:27:24 25 4
gpt4 key购买 nike

我正在写一个简单的待办事项列表。用户输入文本并将其添加为 checkbox。但是我收到了这个错误,我不知道这是怎么回事

INVALID_CHARACTER_ERR: DOM Exception 5
window.onload = function(){
var textBox = document.getElementById("taskInput"),
submitBtn = document.getElementById("submit"),
taskPool = document.getElementById("todoTask");

submitBtn.addEventListener("click", function(){
var task = document.createElement("<input type=\"checkbox\">" + textBox.value + "</input>");
taskPool.appendChild(task);
});

}

最佳答案

document.createElement仅将标签名称作为其参数,您必须在之后设置类型和值

var task = document.createElement("input")
task.type = "checkbox";
task.value = textBox.value;

输入标签也为空,没有结束标签或内部 html,该值设置为标记中的属性。

关于javascript - 获取 INVALID_CHARACTER_ERR : DOM Exception 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11704320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com