简体   繁体   English

VS Code Live Server 扩展添加/复制现有的 HTML 元素

[英]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);

Chrome 开发工具元素选项卡 Live Server 添加的额外蓝色 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.

相关问题 VS Code 的实时服务器扩展不自动重新加载 - Live Server Extension for VS Code not Auto-Reloading JavaScript 路径未加载到 Live Server 扩展(VS 代码) - JavaScript path doesn't load on Live Server extension (VS Code) 实时预览与代码扩展 - Live Preview Vs code Extension Web 蓝牙:无法将 BLE 设备与具有 Live Server VS 代码扩展的移动设备配对 - Web Bluetooth: Can't pair BLE device with Mobile Device with Live Server VS Code extension VS Code 使用 Live Server Extension 将 Javascript 文件呈现为文本 - VS Code just renders Javascript file as Text using Live Server Extension 动作标签在实时服务器与代码中不起作用 - The action tag is not working in live server vs code 实时服务器已安装但无法在 VS 代码中运行 - Live server installed but not working in VS code CSS 未保存在 Live Server 中(VS CODE) - CSS not saving in Live Server (VS CODE) html 文件中的 javascript 在我使用 VS Code 的实时服务器中工作正常,但如果我在本地打开 .html 文件,它就不起作用 - javascript in a html file works fine in my live server using VS Code but if i open the .html file locally it doesn't work 您可以在 Live 服务器扩展 Visual Studio 代码中链接子页面吗 - Can you link subpages in Live server extension Visual studio code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM