获取INVALID_CHARACTER_ERR:DOM异常5 [英] Getting INVALID_CHARACTER_ERR: DOM Exception 5

查看:250
本文介绍了获取INVALID_CHARACTER_ERR:DOM异常5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个简单的待办事项清单。用户输入文本,并将其添加为复选框。但是我收到这个错误我不知道这是什么关于


  INVALID_CHARACTER_ERR:DOM异常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。值+< / input>);
taskPool.appendChild(task);
});

}


解决方案

document.createElement 将标记名称作为参数,您必须设置

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

此外,输入标签为空,没有结束标签或内部html,该值设置为属性在标记。


I'm writing a simple to-do list. that a user input a text and the it's added as a checkbox. But i'm getting this error i have no idea what's it about

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 takes the tag name only as its parameter, you'll have to set the type and value after

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

Also input tags are empty, there are no closing tag or inner html, the value is set as an attribute in markup.

这篇关于获取INVALID_CHARACTER_ERR:DOM异常5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆