2010-12-01 38 views
0

我被教授要求使用http://validator.w3.org/這個網站來驗證我的HTML文件。它給了我錯誤。 第一個錯誤是:HTML家庭作業,沒有通過驗證,但顯示良好

Line 1, Column 1: no document type declaration; implying ""

第二個錯誤是:

Line 11, Column 64: required attribute "ALT" not specified ✉ The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element. Typical values for type are type="text/css" for and type="text/javascript" for .

誰能告訴什麼是錯?它在我的瀏覽器中顯示得很好,我正在使用IE 8。但是教授說,如果它在這個驗證檢查中失敗,那麼這個任務是不完整的。任何幫助都會很棒。

<html> 
<head> 
<title>Randy's first html web page !</title> 
</head> 
<body bgcolor="#000066" text="#00ff44"> 

<h1 align="center"> Hello Professor</h1> 
<h2 align="center"> By: Randy White</h2> 
<p> I haven't done anything like this before.</p> 
<p> Seems to be ok</p> 
<p align="center"><img src="Koala.gif" width="100" height="100"> 
<table border="1"> 
<tr> 
<th>Month</th> 
<th>Day</th> 
<th>Year</th> 
</tr> 
<tr> 
<td>December</td> 
<td>1</td> 
<td>2010</td> 
</tr> 
</table> 
</body> 
</html> 
+0

第1行第1列:序言中的文檔結尾 ✉ 驗證程序收到空白文檔時可能會出現此錯誤。請確保您上傳的文件不是空的,並報告任何差異。 – user770022 2010-12-01 20:16:01

回答

0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
      "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>Randy's first html web page !</title> 
</head> 
<body bgcolor="#000066" text="#00ff44"> 

<h1 align="center"> Hello Professor</h1> 
<h2 align="center"> By: Randy White</h2> 
<p> I haven't done anything like this before.</p> 
<p> Seems to be ok</p> 
<p align="center"><img src="Koala.gif" width="100" height="100" alt="koala image"> 
<table border="1"> 
<tr> 
<th>Month</th> 
<th>Day</th> 
<th>Year</th> 
</tr> 
<tr> 
<td>December</td> 
<td>1</td> 
<td>2010</td> 
</tr> 
</table> 
</body> 
</html> 

我不會回答你的問題,但假設你明天在這裏你必須提供它。

2

你需要一個doctype添加到HTML頁面的頂部,從而使瀏覽器理解它是什麼樣的文件。

<!DOCTYPE html> 

這應該會使其他一些錯誤消失。殘餘是相當自我解釋。添加必需的屬性等。

+0

您顯示的html 5文檔類型非常酷,但仍然不被所有瀏覽器支持,請牢記這一點! P.s的HTML應該是大寫的。 – Michael 2010-12-01 20:05:10

+2

@Michael:不,html不應該(或者至少不需要)被提升。 [規範的工作草案](http://dev.w3.org/html5/spec/Overview.html#the-doctype)以小寫字母表示,但表示不區分大小寫。 – 2010-12-01 20:08:51

2

裏面你需要一個ALT標記您的img標籤...

<img src='koala.jpg' alt='A Koala!'>

文檔標籤的一個例子是這樣(就在這個頁面獲取)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

w3c有更多信息。

2

對於一個有效的HTML文件,你需要在HTML之前有一個標籤,它需要成爲第一行。請參閱這裏以獲取更多信息http://www.w3.org/QA/2002/04/valid-dtd-list.html

第二個錯誤:您需要在您的img標記中使用alt =「...」屬性,這應該是與圖像有關的信息,在圖像不可用的情況下,不會被用戶看到。

0

HTML根據XML(或SGML)規則進行驗證。瀏覽器已經被開發來接受不符合標準的HTML,因此瀏覽器不是有效性的測試。同樣,還有一些很好的做法,例如添加ALT屬性(用於輔助功能)。有視力的人類不需要它們,但許多其他人卻需要它們。

因此,創建一致性文檔總是一個好習慣。