javascript - “未捕获的层次结构请求错误 : new line tag after createTextNode

标签 javascript

这是我试图使其工作的代码:

var aform = document.createElement("form");
var model = document.createTextNode("xyz");
var newLine = document.createElement('br');
model.appendChild(newLine);
var status = document.createTextNode("abc");

aform.appendChild(model);
aform.appendChild(status);

$("#someDiv").append(aform);

当我尝试运行代码时,它总是给我错误

"Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': This node type does not support this method."

有人可以建议一下为什么它不起作用吗?我只想在创建文本节点 xyz 和 abc 之后换一个新行。

最佳答案

你可以用 jQuery 完成所有的事情,因为你无论如何都在使用它:

$("#someDiv").append("<form>xyz<br>abc</form>");

关于javascript - “未捕获的层次结构请求错误 : new line tag after createTextNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33618644/

相关文章:

javascript - 用图像替换 CHOOSE FILE

javascript - 未捕获错误 : [$injector:modulerr] Failed to instantiate module showsApp due to: Error: [ng:areq] Argument 'fn' is not a function, 获取字符串

javascript - HTML5 移动网站上的动画

javascript - 正则表达式使用javascript用英语和阿拉伯语字符串中的空格替换特殊字符

php - 人力车 : data for multiple series not working

javascript - 这个 jQuery 示例有什么问题?

javascript - 对 Textarea 的内容使用 .match()

Javascript 转换

javascript - 为什么 AngularJS 中的 $event.preventDefault() 不阻止出现上下文菜单?

javascript - 在 html 文件中使用 JavaScript chop 变量