简体   繁体   English

W3C标记验证错误

[英]W3C markup validation errors

I tried W3C Markup validation with a simple HTML page. 我尝试使用简单的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>

and got the following errors 并出现以下错误

在此处输入图片说明

I guess in the noscript tag (or generally in the head tag itself) using DOM elements like a is not okay, Is there any alternative to that? 我猜在noscript标记(或通常在head标记本身)中使用DOM元素(例如a是不行的,还有其他替代方法吗? ie if script is not found provide a link to a page that doesn't need script 即,如果找不到脚本,请提供指向不需要脚本的页面的链接

and any idea as to why I am getting the errors for link & body tags? 以及关于为什么我会收到linkbody标签错误的任何想法? Thanks 谢谢

link tag doesn't have a close tag, </link> . link标记没有结束标记</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. 另外,您还需要在body标签内部和head标签之间移动<noscript>标签,因为它包含文本内容。

Reference 参考

Sitepoint Reference 网站参考


Though, using something like this is valid if you place in the head tag 1 . 但是,如果将这样的东西放在head标签1中,则是有效的。

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

1. In a head element, if scripting is disabled for the noscript element 1. 在head元素中,如果noscript元素的脚本禁用
The noscript element must contain only link , style , and meta elements. noscript元素必须仅包含linkstylemeta元素。

In a head element, if scripting is enabled for the noscript element 在head元素中,如果为noscript元素启用了noscript
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. noscript元素只能包含文本,除了调用HTML片段解析算法时,以noscript元素为上下文元素,以文本内容为输入,必须生成仅由linkstylemeta元素组成的节点列表如果它们是noscript元素的子元素,并且没有解析错误,则将是符合条件的。

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>

Check you style link which is not right. 检查您的样式链接不正确。 Style link should be self close. 样式链接应该是自关闭的。 ie

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

and because there is written text not linked style or script so it should be under body tag. 并且因为有书面文字没有链接的样式或脚本,所以它应该在body标签下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM