2013-09-23 161 views
0

我試着用簡單的HTML頁面W3C Markup validationW3C標記驗證錯誤

<!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> 

,得到了以下錯誤

enter image description here

我想在noscript標籤(或一般是在頭標籤本身)使用DOM元素,如a是不行的,有沒有替代品那?即如果腳本未找到提供一個鏈接到一個頁面,不需要腳本

和任何想法,爲什麼我得到的錯誤link & body標籤?謝謝

+1

'link'是自我關閉標記。你不需要''。 – hallaji

+0

@hallaji,yea沒有注意到,謝謝:) – rps

回答

5

link標記沒有結束標記,</link>。因此,這是無效的。如果您想在線關閉它,像這樣做:

<link ... /> 

另外,你需要在你<noscript>標籤轉移body標籤內部和head標籤之間,因爲它包含文本內容。

Reference

Sitepoint Reference


雖然,使用的東西一樣,如果你在head標籤把這個有效。

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

1.在頭元件,如果腳本是用於noscript元件
   的noscript元件必須僅包含linkstyle,和meta元件禁用。

在頭元件,如果腳本被啓用爲noscript元件
noscript元件必須僅包含文本,除了 與非腳本 元素作爲上下文元素和文本調用HTML片段分析算法作爲輸入的內容必須爲 產生的節點列表僅包含link,stylemeta 如果元素是子元素的子元素並且沒有解析錯誤,則該元素符合要求。

正確的標記

<!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> 
+4

從'if if ie IE 8'刪除''。 – hallaji

+0

@hallaji感謝您指出,我只是錯過了:) –

+0

我對待noscript像腳本,甚至沒有想到把它放在頭部的良好做法:),謝謝! – rps

0

檢查你的風格鏈接,是不正確的。風格鏈接應該是自我關閉的。即

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

而且由於有寫入文本沒有鏈接樣式或腳本,所以它應該在body標籤下。