本文介绍了未捕获的错误:NOT_FOUND_ERR:用于appendChild调用的DOM异常8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误发生在最后此代码段的行:
The error occurs on the last line of this snippet:
var anchor = "<a id=\"hostname\" href=\"" + destination + "\"> "+ imagename + "</a>";
var specialdiv = document.getElementById("specialdiv");
console.log("div: " + specialdiv);
specialdiv.appendChild(anchor);
真的没有其他事情......我验证了 specialdiv
不是null或类似的东西。任何人都可以解释为什么我在该行上收到此错误?
There's really nothing else going on... I verified that specialdiv
isn't null or something like that. Can anyone explain why I'm getting this error on that line?
推荐答案
不传递字符串,而是传递元素
don't pass a string, but an element
var link = document.createElement('a');
link.innerHTML = imagename;
link.id = "hostname";
link.href = destination;
var specialdiv = document.getElementById("specialdiv");
specialdiv.appendChild(link);
这篇关于未捕获的错误:NOT_FOUND_ERR:用于appendChild调用的DOM异常8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!