[英]VS Code Live Server extension adding/duplicating existing HTML element
I'm using the Liver Server extension in VS Code to see the result of some HTML/JS I'm experimenting with, however, it appears Live Server is injecting it's own duplication of one of the HTML elements (in this case an empty div) and joining it onto the bottom of the document.我在 VS Code 中使用 Liver Server 扩展来查看我正在试验的一些 HTML/JS 的结果,但是,Live Server 似乎正在注入它自己的 HTML 元素之一的副本(在本例中为空 div ) 并将其连接到文档的底部。 I'm fairly certain Live-Server is the issue here because I've had a look at my code on Codepen and the issue does not appear.我相当确定 Live-Server 是这里的问题,因为我已经在 Codepen 上查看了我的代码并且没有出现问题。
I hope providing a link to Codepen is ok: https://codepen.io/UnmadeBed/pen/PoEoMKy我希望提供一个指向 Codepen 的链接是可以的: https://codepen.io/UnmadeBed/pen/PoEoMKy
main.js:主.js:
// grab elements from HTML doc
const body = document.querySelector('body');
// container to hold the grid divs
const containerDiv = document.createElement('div');
containerDiv.style.backgroundColor = 'red';
containerDiv.style.height = '500px';
containerDiv.style.width = '500px';
body.appendChild(containerDiv);
const div = document.createElement('div');
containerDiv.appendChild(div);
Solved.解决了。 It turns out I was accidentally styling a hidden div used by Live Server, as opposed to Live Server duplicating anything.事实证明我不小心设计了 Live Server 使用的隐藏 div,而不是 Live Server 复制任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.