4

它在谷歌浏览器中看起来像这样:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>

为什么没有按预期转变?

编辑:是的,该文件确实有一个 .html 文件名。根据我正在使用的教程,我不确定它是否需要一个标题,它说它应该在没有标题的情况下正确渲染?这一切都是新的,所以我不确定。

编辑:当我用 textedit 打开它时,我得到了这个:

<!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">&lt;html&gt;</p>
<p class="p1">&lt;head&gt;</p>
<p class="p1">&lt;title&gt;Hello World!&lt;/title&gt;</p>
<p class="p1">&lt;/head&gt;</p>
<p class="p1">&lt;body&gt;</p>
<p class="p1">&lt;h1 align="center"&gt;Hello World!&lt;br/&gt;Welcome to My Web Server.&lt;/h1&gt;</p>
<p class="p1">&lt;/body&gt;</p>
<p class="p1">&lt;/html&gt;</p>
</body>
</html>

我根本不记得像这样保存它。

4

3 回答 3

11

您是如何创建网页的?您使用的编辑器可能会转换 html,使其显示“<”而不是呈现它们

在记事本中打开文件,检查内容是否为:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>

并不是

&lt;html&gt;
......
&lt;/html&gt;

确保使用 .html 扩展名保存文件

于 2011-07-20T08:00:38.470 回答
5

它应该由浏览器呈现,而不是网络服务器。检查 HTTP 标头“Content-Type”。它应该是类似“Content-Type: text/html; charset=utf-8”的内容。

鉴于您使用 Chrome,请使用以下步骤加载开发人员工具;

  1. 右键单击页面->选择“检查元素”
  2. 转到网络选项卡
  3. 加载您尝试检查的页面
  4. 选择您要检查标头等的页面的 URL
于 2011-07-20T08:00:03.730 回答
3

从您发布的文件内容中包含说明:

<meta name="Generator" content="Cocoa HTML Writer">

基本上,您的文本编辑器认为您想输入的“文本”转换为网页。因此,它将它保存为一个网页,可以准确显示您输入的内容。

你是怎么保存文件的?如果您使用任何将“转换”或“导出”到 HTML 的内容,那就是罪魁祸首。只需使用常规的“保存”选项。如果这不起作用:找一个更好的编辑器,一个不会试图比你更聪明的编辑器。

于 2011-07-20T08:19:07.190 回答