VSCode中HTML无法正常显示:Chrome直接展示代码而非网页
解决Chrome直接显示HTML代码而非网页的问题
检查文件扩展名
务必确保文件后缀是.html,而非.txt或无后缀。保存文件时,文件名要明确写xxx.html(比如index.html),保存类型选择“所有文件”,防止系统自动添加.txt后缀。正确打开文件方式
不要依赖VSCode的预览面板,直接找到文件所在的本地文件夹,双击文件让Chrome打开;或者在VSCode编辑器空白处右键,选择“在默认浏览器中打开”(若没对应插件,手动找文件打开更可靠)。确认文件格式
你的HTML代码结构是正常的,但要保证文件是纯文本格式。可以用记事本打开文件,确认内容无误后,另存为.html格式,编码选择UTF-8。
你的代码示例:
<html> <body> <h1>The Template Element</h1> <p>Click the button below to display the hidden content from the template element.</p> <button onclick = "showContent()"> Button</button> <h2>Flower</h2> <img src = "images/Cello Wallpapers - Wallpaper Cave.jpg" width = "214" height ="204"> </body> </html>
内容的提问来源于stack exchange,提问作者Om Vyas
相关产品推荐
相关产品推荐

