在什么情况下,从文档下显示的片段添加的元素?

时间:2013-10-24 20:29:50

标签: javascript visual-studio

我有一个javascript项目,有一些代码我用来在div中创建一些子div:

var fragment = document.createDocumentFragment();
// code here to add divs in fragment
this._container.appendChild(fragment);

''是我创建的对象, _container 是div。 this._container肯定是一个现有的div。在this._container.appendChild(片段)之后,div正确显示在我的html表单上。

当我在Visual Studio中调试它时,片段中的元素显示在文档下。

enter image description here

有人知道为什么吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

这取决于代码运行的上下文,它设置 this 的值。

检查this._container的值。