为什么我的网络浏览器上没有呈现 html?
它在 Google Chrome 中看起来像这样:
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>
为什么它没有按预期进行转换?
编辑:是的,该文件确实有一个 .html 文件名。我不确定它是否应该需要一个标题,但根据我正在使用的教程,它说它应该在没有标题的情况下正确渲染?这都是新的,所以我不确定。
编辑:当我用文本编辑打开它时,我得到这个:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class="p1"><html></p>
<p class="p1"><head></p>
<p class="p1"><title>Hello World!</title></p>
<p class="p1"></head></p>
<p class="p1"><body></p>
<p class="p1"><h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1></p>
<p class="p1"></body></p>
<p class="p1"></html></p>
</body>
</html>
我根本不记得像这样保存它。
It just appears like this in Google Chrome:
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>
Why isn't it transforming as expected?
Edit: Yes the file does have an .html filename. I'm not sure it should need a header yet according to a tutorial I'm using which says that it should render correctly without one? All new to this so I'm unsure.
Edit: When I open it with textedit, I get this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class="p1"><html></p>
<p class="p1"><head></p>
<p class="p1"><title>Hello World!</title></p>
<p class="p1"></head></p>
<p class="p1"><body></p>
<p class="p1"><h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1></p>
<p class="p1"></body></p>
<p class="p1"></html></p>
</body>
</html>
I don't remember saving it like this at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是如何创建网页的?您使用的编辑器可能会转换 html,使其显示“<”而不是渲染它们
在记事本中打开文件,检查内容是否为:
并且不要
确保使用 .html 扩展名保存文件
How did you create the web page? It is possible that the editor that you used converted the html so that it shows "<" instead of rendering them
Open the file in notepad, check that the contents are:
and not
make sure you save your file with a .html extension
它应该由浏览器而不是网络服务器呈现。检查 HTTP 标头“Content-Type”。它应该显示为“Content-Type: text/html; charset=utf-8”。
鉴于您使用 Chrome,请使用以下步骤加载开发人员工具;
It should be rendered by the browser, not the webserver. Check the HTTP headers "Content-Type". It should read something like "Content-Type: text/html; charset=utf-8".
Given your using Chrome, load up developer tools using the following steps;
您发布的文件内容包含说明:
基本上,您的文本编辑器认为您想要将您输入的“文本”转换为网页。因此它将其保存为一个网页,该网页准确显示您输入的内容。
你是如何保存文件的?如果您使用了任何“转换”或“导出”为 HTML 的内容,那就是罪魁祸首。只需使用常规的“保存”选项即可。如果这不起作用:找一位更好的编辑,一个不会试图比你更聪明的编辑。
From the file content you posted contains the explanation:
Basically, your text editor thought you wanted to convert the "text" you had entered to a webpage. So it saved it as a webpage that displays exactly what you have entered.
How did you save the file? If you used anything that says "convert" or "export" to HTML, that's the culprit. Just use the regular "save" option. And if that doesn't work: get a better editor, one that doesn't try to be smarter than you.