【问题标题】:W3C markup validation errorsW3C 标记验证错误
【发布时间】:2013-09-23 06:10:05
【问题描述】:

我用一个简单的 HTML 页面尝试了W3C Markup validation

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Title</title>
    <script src="script/myScript.js" type="text/javascript"></script>
    <link href="style/theme.css" rel="stylesheet"></link> 
     <!--[if lte IE 8]>
    <link href="style/themeIE8.css" rel="stylesheet"></link>
    <![endif]-->     
    <noscript>Please enable JavaScript in your browser to view this page properly, to view the basic page of the site click the link <a href="no-javascipt/main.aspx">main.aspx</a>
   </noscript>

</head>
<body class="layout">
   <div class="header"></div>
   <div class="content"></div>
   <div class="footer"></div>
</body>
</html>

并得到以下错误

我猜想在noscript 标签(或通常在head 标签本身)中使用像a 这样的DOM 元素是不行的,有什么替代方法吗?即,如果找不到脚本,请提供指向不需要脚本的页面的链接

你知道为什么我会收到linkbody 标签的错误吗?谢谢

【问题讨论】:

  • link 是自关闭标签。你不需要&lt;/link&gt;
  • @hallaji,是的,没注意到,谢谢 :)

标签: html w3c-validation noscript


【解决方案1】:

link 标签没有结束标签,&lt;/link&gt;。因此,它是无效的。如果你想内联关闭它,这样做:

<link ... />

此外,您需要将&lt;noscript&gt; 标记移到body 标记内和head 标记之间,因为它包含文本内容。

Reference

Sitepoint Reference


不过,如果您将其放入 head 标签 1,则使用类似的内容是有效的。

<noscript><link href="style/theme.css" rel="stylesheet" /></noscript>

1.在 head 元素中,如果 noscript 元素的脚本被禁用
noscript 元素必须仅包含 linkstylemeta 元素。

在 head 元素中,如果为 noscript 元素启用脚本
noscript 元素必须只包含文本,除了 使用 noscript 调用 HTML 片段解析算法 元素作为上下文元素,文本内容作为输入必须 生成仅包含 linkstylemeta 的节点列表 如果它们是 noscript 元素,并且没有解析错误。

正确的标记

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Title</title>
    <script src="script/myScript.js" type="text/javascript"></script>
    <link href="style/theme.css" rel="stylesheet" />
     <!--[if lte IE 8]>
    <link href="style/themeIE8.css" rel="stylesheet" />
    <![endif]-->     
</head>
<body class="layout">
<noscript>Please enable JavaScript in your browser to view this page properly, to view the basic page of the site click the link <a href="no-javascript/main.aspx">main.aspx</a>
   </noscript>
   <div class="header"></div>
   <div class="content"></div>
   <div class="footer"></div>
</body>
</html>

【讨论】:

  • 也从if lte IE 8 中删除&lt;/link&gt;
  • 我把 noscript 当作脚本来对待,甚至没有想过把它放在头脑之外作为好的做法 :),谢谢!
  • @rps 好吧,这不是好的做法,它高于无效和有效\您可以参考文档..欢迎您:)
【解决方案2】:

检查您的样式链接是否不正确。样式链接应该是自关闭的。即

<link href=".."  rel="stylesheet" />

因为有文字没有链接样式或脚本所以它应该在body标签下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    相关资源
    最近更新 更多