0

我用一个简单的 HTML 页面尝试了W3C 标记验证。

<!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标签中(或通常在头标签本身中)使用 DOM 元素a是不行的,有没有其他选择?即,如果找不到脚本,则提供指向不需要脚本的页面的链接

以及为什么我会收到link&body标签的错误的任何想法?谢谢

4

2 回答 2

4

link tag doesn't have a close tag, </link>. As such, it's invalid. If you want to close it inline, do it like this:

<link ... />

Also, you need to shift your <noscript> tag inside the body tag and between the head tag as it contains text content.

Reference

Sitepoint Reference


Though, using something like this is valid if you place in the head tag 1.

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

1. In a head element, if scripting is disabled for the noscript element
   The noscript element must contain only link, style, and meta elements.

In a head element, if scripting is enabled for the noscript element
The noscript element must contain only text, except that invoking the HTML fragment parsing algorithm with the noscript element as the context element and the text contents as the input must result in a list of nodes that consists only of link, style, and meta elements that would be conforming if they were children of the noscript element, and no parse errors.

Correct Markup

<!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>
于 2013-09-23T06:14:48.667 回答
0

检查你不正确的样式链接。样式链接应该是自关闭的。IE

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

并且因为没有链接样式或脚本的书面文本,所以它应该在正文标签下。

于 2013-09-23T07:03:23.407 回答