diff --git a/files/zh-tw/web/guide/ajax/getting_started/index.html b/files/zh-tw/web/guide/ajax/getting_started/index.html deleted file mode 100644 index 07f56d952d1ece..00000000000000 --- a/files/zh-tw/web/guide/ajax/getting_started/index.html +++ /dev/null @@ -1,287 +0,0 @@ ---- -title: 入門篇 -slug: Web/Guide/AJAX/Getting_Started -tags: - - AJAX - - API - - Advanced - - JavaScript - - WebMechanics - - XMLHttpRequest -translation_of: Web/Guide/AJAX/Getting_Started ---- -
這篇文章說明 AJAX 相關技術的基礎,並提供兩個簡單的實際操作範例供您入門。
- -AJAX 代表 Asynchronous JavaScript And XML,即非同步 JavaScript 及 XML。簡單地說,AJAX 使用 {{domxref("XMLHttpRequest")}} 物件來與伺服器進行通訊。它可以傳送並接收多種格式的資訊,包括 JSON、XML、HTML、以及文字檔案。AJAX 最吸引人的特點是「非同步」的本質,這代表它可以與伺服溝通、交換資料、以及更新頁面,且無須重整網頁。
- -有兩項即將討論到的特點如下︰
- -為了使用 JavaScript 向伺服器發送 HTTP 請求,便需要一個能夠提供相關功能的類別實體(an instance of a class)。這樣的類別最初由 Internet Explorer 以 ActiveX 物件的方式引入,稱為 XMLHTTP
。Mozilla、Safari 及其他瀏覽器則隨後跟進,實作了 XMLHttpRequest
類別,以提供微軟最初的 ActiveX 物件中的方法及屬性。
因此,為了建立能夠跨瀏覽器的物件實體,可以這麼寫:
- -// Old compatibility code, no longer needed. -if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+ ... - httpRequest = new XMLHttpRequest(); -} else if (window.ActiveXObject) { // IE 6 and older - httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); -} -- -
部分版本的 Mozilla 瀏覽器,在伺服器送回的資料未含 XML mime-type
標頭(header)時會出錯。為了避免這個問題,你可以用下列方法覆寫伺服器傳回的檔頭,以免傳回的不是 text/xml
。
httpRequest = new XMLHttpRequest(); -httpRequest.overrideMimeType('text/xml'); -- -
接下來是要決定伺服器傳回資料後的處理方式,此時你只要以 onreadystatechange
這個屬性指明要處理傳回值的 JavaScript 函式名稱即可,例如:
httpRequest.onreadystatechange = nameOfTheFunction;
-
-注意,指定的函式名稱後不加括號也沒有參數。這只是簡單的賦值,而非真的呼叫函數。除了指定函式名稱外,你也能用 Javascript 即時定義函式的技巧(稱為〝匿名函數〞)來定一個新的處理函式,如下:
- -httpRequest.onreadystatechange = function(){ - // 做些事 -}; -- -
決定處理方式之後你得確實發出 request,此時需叫用 HTTP request 類別的 open()
及 send()
方法,如下:
httpRequest.open('GET', 'http://www.example.org/some.file', true); -httpRequest.send(); -- -
open()
的第一個參數是 HTTP request 的方法,也就是從 GET、POST、HEAD 等伺服器支援的方法中擇一使用。為遵循 HTTP 標準,請記得這些方法都是大寫,否則有的瀏覽器(如 Firefox)不會處理這些請求。其他可用的 HTTP request 方法的列表請參考 W3C 規格書。open()
時會出現「權限不足,拒絕存取」那類的錯誤。常見的錯誤多為在 domain.tld 的網站下呼叫 www.domain.tld 中的網頁,僅是一點點差別都不行。TRUE
則即使伺服器尚未傳回資料也會繼續執行其餘的程式,這也就是 AJAX 中第一個 A 代表的意義。send()
的參數在以 POST 發出 request 時,可以是任何想傳給伺服器的東西,而資料則以查詢字串的方式列出,例如:
"name=value&anothername="+encodeURIComponent(myVar)+"&so=on"
-
-不過如果你想要以 POST 方式傳送資料,則必須先將 MIME 型態改好,如下:
- -httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); -- -
否則伺服器就不會理你傳過來的資料了。
- -傳出 request 時必須提供處理傳回值的函數名稱,這個函數是用來處理伺服器的回應。
- -httpRequest.onreadystatechange = nameOfTheFunction; -- -
那麼來看看這個函數該做些什麼。首先,它必須檢查 request 目前的狀態。如果狀態值為 4 代表伺服器已經傳回所有資訊了,便可以開始解析所得資訊。
- -if (httpRequest.readyState === XMLHttpRequest.DONE) { - // 一切 ok, 繼續解析 -} else { - // 還沒完成 -} -- -
readyState
所有可能的值如下:
接下來要檢查伺服器傳回的 HTTP 狀態碼。所有狀態碼列表可於 W3C 網站上查到,但我們要管的是 200 OK
這種狀態。
if (httpRequest.status === 200) { - // 萬事具備 -} else { - // 似乎有點問題。 - // 或許伺服器傳回了 404(查無此頁) - // 或者 500(內部錯誤)什麼的。 -} -- -
檢查傳回的 HTTP 狀態碼後,要怎麼處理傳回的資料就由你決定了。有兩種存取資料的方式:
- -httpRequest.responseText
– 這樣會把傳回值視為字串用httpRequest.responseXML
– 這樣會把傳回值視為 XMLDocument
物件,而後可用 JavaScript DOM 相關函式處理好,接著就做一次簡單的 HTTP 範例,演示方才的各項技巧。這段 JavaScript 會向伺服器要一份裡頭有「I'm a test.」字樣的 HTML 文件(test.html
),而後以 alert()
將文件內容列出。
<button id="ajaxButton" type="button">Make a request</button> - -<script> -(function() { - var httpRequest; - document.getElementById("ajaxButton").addEventListener('click', makeRequest); - - function makeRequest() { - httpRequest = new XMLHttpRequest(); - - if (!httpRequest) { - alert('Giving up :( Cannot create an XMLHTTP instance'); - return false; - } - httpRequest.onreadystatechange = alertContents; - httpRequest.open('GET', 'test.html'); - httpRequest.send(); - } - - function alertContents() { - if (httpRequest.readyState === XMLHttpRequest.DONE) { - if (httpRequest.status === 200) { - alert(httpRequest.responseText); - } else { - alert('There was a problem with the request.'); - } - } - } -})(); -</script> -- -
在此範例中:
- -makeRequest()
函式,亦傳入參數值 test.html
(也就是那份 HTML 檔的名稱,放在同目錄下)onreadystatechange
指定的 alertContents()
函式alertContents()
檢查回應是否正常,而後以 alert()
將 test.html
的內容列出Content-Type: application/xml
,IE將會在我們試圖運作的XML項目行下,回應一個"Object Expected" 的錯誤。Cache-Control: no-cache
,那瀏覽器將會藏匿response並且不再重新傳送request,造成除錯上的挑戰。我們也可以增加一個 always-different GET 參數,像是 timestamp 或 random number (詳見bypassing the cache)httpRequest
variable is used globally, competing functions calling makeRequest()
can overwrite each other, causing a race condition. Declaring the httpRequest
variable local to a closure containing the AJAX functions avoids this.In the event of a communication error (such as the server going down), an exception will be thrown in the onreadystatechange
method when accessing the response status. To mitigate this problem, you could wrap your if...then
statement in a try...catch
:
function alertContents() { - try { - if (httpRequest.readyState === XMLHttpRequest.DONE) { - if (httpRequest.status === 200) { - alert(httpRequest.responseText); - } else { - alert('There was a problem with the request.'); - } - } - } - catch( e ) { - alert('Caught Exception: ' + e.description); - } -} -- -
前面的例子中,在收到 HTTP 傳回值後我們以物件的 reponseText
屬性接收 test.html
檔案的內容,接著來試試 responseXML
屬性。
首先,我們得做個格式正確的 XML 文件以便稍後取用。文件 (test.xml
) 內容如下:
<?xml version="1.0" ?> -<root> - I'm a test. -</root> -- -
在程式中,我們叫用檔案的地方只須略事修改如下:
- -... -onclick="makeRequest('test.xml')"> -... -- -
接著在 alertContents()
中,我們把 alert(http_request.responseText);
改成這樣:
var xmldoc = httpRequest.responseXML; -var root_node = xmldoc.getElementsByTagName('root').item(0); -alert(root_node.firstChild.data); -- -
這樣一來我們便可取得 responseXML
所傳回的 XMLDocument
物件,而後以 DOM 方法取用 XML 文件的內容。你可以參考 test.xml
的原始碼 以及修改過後的測試程式。
關於 DOM 方法,請參考 Mozilla DOM 文件。
- -Finally, let's send some data to the server and receive a response. Our JavaScript will request a dynamic page this time, test.php
, which will take the data we send and return a "computed" string - "Hello, [user data]!" - which we'll alert().
First we'll add a text box to our HTML so the user can enter their name:
- -<label>Your name: - <input type="text" id="ajaxTextbox" /> -</label> -<span id="ajaxButton" style="cursor: pointer; text-decoration: underline"> - Make a request -</span>- -
We'll also add a line to our event handler to get the user's data from the text box and send it to the makeRequest()
function along with the URL of our server-side script:
document.getElementById("ajaxButton").onclick = function() { - var userName = document.getElementById("ajaxTextbox").value; - makeRequest('test.php',userName); - }; -- -
We need to modify makeRequest()
to accept the user data and pass it along to the server. We'll change the request method from GET
to POST
, and include our data as a parameter in the call to httpRequest.send()
:
function makeRequest(url, userName) { - - ... - - httpRequest.onreadystatechange = alertContents; - httpRequest.open('POST', url); - httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - httpRequest.send('userName=' + encodeURIComponent(userName)); - } -- -
The function alertContents()
can be written the same way it was in Step 3 to alert our computed string, if that's all the server returns. However, let's say the server is going to return both the computed string and the original user data. So if our user typed "Jane" in the text box, the server's response would look like this:
{"userData":"Jane","computedString":"Hi, Jane!"}
To use this data within alertContents()
, we can't just alert the responseText
, we have to parse it and alert computedString
, the property we want:
function alertContents() { - if (httpRequest.readyState === XMLHttpRequest.DONE) { - if (httpRequest.status === 200) { - var response = JSON.parse(httpRequest.responseText); - alert(response.computedString); - } else { - alert('There was a problem with the request.'); - } - } -}- -
The test.php file should contain the following:
$name = (isset($_POST['userName'])) ? $_POST['userName'] : 'no name';
-$computedString = "Hi, " . $name;
-$array = ['userName' => $name, 'computedString' => $computedString];
-echo json_encode($array);
-
-For more on DOM methods, be sure to check Mozilla's DOM implementation documents.
非同步 JavaScript 及 XML(Asynchronous JavaScript and XML,AJAX) 並不能稱做是種「技術」,而是 2005 年時由 Jesse James Garrett 所發明的術語,描述一種使用數個既有技術的「新」方法。這些技術包括 HTML 或 XHTML、層疊樣式表、JavaScript、文件物件模型、XML、XSLT 以及最重要的 XMLHttpRequest 物件。
- 當這些技術被結合在 Ajax 模型中,Web 應用程式便能快速、即時更動介面及內容,不需要重新讀取整個網頁,讓程式更快回應使用者的操作。
雖然 X 在 Ajax 中代表 XML,但由於 JSON 的許多優點,如輕量以及其本身就是 JavaScript 的一部分等,讓現今 JSON 比起 XML 被更廣泛的使用。JSON 與 XML 兩者都被用來在 Ajax 模型中包裝資訊。
-XMLHttpRequest
API 是 Ajax 的核心。這篇文章將解釋如何使用一些 Ajax 技術,例如:
- FormData
物件responseType
property of the XMLHttpRequest object can be set to change the expected response type from the server. Possible values are the empty string (default), "arraybuffer"
, "blob"
, "document"
, "json"
, and "text"
. The response
property will contain the entity body according to responseType
, as an ArrayBuffer
, Blob
, Document
, JSON
, or string. This article will show some Ajax I/O techniques.FileReader
APIFileReader
API lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File
or Blob
objects to specify the file or data to read. File objects may be obtained from a FileList
object returned as a result of a user selecting files using the "><input>
element, from a drag and drop operation's DataTransfer
object, or from the mozGetAsFile()
API on an HTMLCanvasElement
.XMLHttpRequest
, which originally supported only XML parsing. This feature allows Web apps to obtain an HTML resource as a parsed DOM using XMLHttpRequest
.HTML, XHTML, CSS, DOM, JavaScript, XML, XMLHttpRequest, XSLT, DHTML, Same Origin Policy
- -{{ListSubpages}}
diff --git a/files/zh-tw/web/guide/ajax/index.md b/files/zh-tw/web/guide/ajax/index.md new file mode 100644 index 00000000000000..dd5e69de8396fd --- /dev/null +++ b/files/zh-tw/web/guide/ajax/index.md @@ -0,0 +1,87 @@ +--- +title: Ajax +slug: Web/Guide/AJAX +translation_of: Web/Guide/AJAX +--- +**[入門篇](/zh-TW/docs/Web/Guide/AJAX/Getting_Started)** +Ajax 簡介。 + +非同步 JavaScript 及 XML(Asynchronous JavaScript and XML,AJAX)並不能稱做是種「技術」,而是 2005 年時由 Jesse James Garrett 所發明的術語,描述一種使用數個既有技術的「新」方法。這些技術包括 [HTML](/zh-TW/docs/HTML) 或 [XHTML](/zh-TW/docs/XHTML)、[層疊樣式表](/zh-TW/docs/CSS)、[JavaScript](/zh-TW/docs/JavaScript)、[文件物件模型](/zh-TW/docs/DOM)、[XML](/zh-TW/docs/XML)、[XSLT](/zh-TW/docs/XSLT) 以及最重要的 [XMLHttpRequest 物件](/zh-TW/docs/XMLHttpRequest)。 +當這些技術被結合在 Ajax 模型中,Web 應用程式便能快速、即時更動介面及內容,不需要重新讀取整個網頁,讓程式更快回應使用者的操作。 + +雖然 X 在 Ajax 中代表 XML,但由於 [JSON](/zh-TW/docs/JSON) 的許多優點,如輕量以及其本身就是 JavaScript 的一部分等,讓現今 JSON 比起 XML 被更廣泛的使用。JSON 與 XML 兩者都被用來在 Ajax 模型中包裝資訊。 + +## 文件 + +- [入門篇](/zh-TW/docs/AJAX/Getting_Started) + - : 這篇文章會指引你瞭解 Ajax 的基礎知識並提供了兩個簡單的動手做範例來入門。 +- [使用 XMLHttpRequest API](/zh-TW/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest) + - : [`XMLHttpRequest` API](/zh-TW/docs/DOM/XMLHttpRequest) 是 Ajax 的核心。這篇文章將解釋如何使用一些 Ajax 技術,例如: [分析及處理伺服器回應](/zh-TW/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Handling_responses) + - [監視請求進度](/zh-TW/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress) + - [提交表單與上傳二進制檔案](/zh-TW/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Submitting_forms_and_uploading_files) – 使用*單純的* Ajax,或使用 [`FormData`](/zh-TW/docs/DOM/XMLHttpRequest/FormData) 物件 + - [建立同步或非同步請求](/zh-TW/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest#Types_of_requests) + - 在 [Web workers](/zh-TW/docs/DOM/Worker) 中使用 Ajax +- [Fetch API](/zh-TW/docs/Web/API/Fetch_API) + - : Fetch API 提供了取得資源(fetching resources)的介面(interface)。這似乎對於曾使用過 {{domxref("XMLHTTPRequest")}} 的人而言並不陌生,然而這個 API 提供一個更強大且彈性的功能集。 +- [Server-sent events](/zh-TW/docs/Server-sent_events) + - : 傳統上來說,一個網頁必須送出 request 到伺服器來得到新的資料,也就是說,網頁藉由 server-sent 事件從伺服器請求 (request) 資料,伺服器在任何時候都能送新的資料給網頁,藉由推送訊息到網頁。這些傳入的訊息可以被視為網頁中的 _[事件](/zh-TW/docs/DOM/event)_ + 資料,請參見 [使用 server-sent event ](/zh-TW/docs/Server-sent_events/Using_server-sent_events)。 +- [_Pure-Ajax_ navigation example](/zh-TW/docs/Web/Guide/DOM/Manipulating_the_browser_history/Example) + - : This article provides a working (minimalist) example of a _pure-Ajax_ website composed only of three pages. +- [Sending and Receiving Binary Data](/zh-TW/docs/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data) + - : The `responseType` property of the XMLHttpRequest object can be set to change the expected response type from the server. Possible values are the empty string (default), `"arraybuffer"`, `"blob"`, `"document"`, `"json"`, and `"text"`. The `response` property will contain the entity body according to `responseType`, as an `ArrayBuffer`, `Blob`, `Document`, `JSON`, or string. This article will show some Ajax I/O techniques. +- [XML](/zh-TW/docs/XML) + - : 可擴展標記語言(The Extensible Markup Language, XML)是 W3C 推薦的用於創建特殊用途標記語言的通用標記語言。它是 SGML 的簡化子集,能夠描述許多不同類型的數據。其主要目的是促進不同系統間的數據共享,特別是通過網際網路連接的系統。 +- [JXON](/zh-TW/docs/JXON) + - : JXON 代表無損耗 **J**avascript **X**ML **O**bject **N**otation, 是一個通用名稱,用來定義使用 XML 的 Javascript 物件樹(JSON) 的通用名稱。 +- [解析和序列化 XML](/zh-TW/docs/Parsing_and_serializing_XML) + - : 如何從一串字串,一個檔案中透過 Javascript 解析一個 XML 文件 ,以及如何將 XML 檔案序列化成字串、Javascript 物件樹(JXON) 或檔案。 +- [XPath](/zh-TW/docs/XPath) + - : XPath stands for **X**ML **Path** Language, it uses a non-XML syntax that provides a flexible way of addressing (pointing to) different parts of an [XML](/zh-TW/docs/XML) document. As well as this, it can also be used to test addressed nodes within a document to determine whether they match a pattern or not. +- [The `FileReader` API](/zh-TW/docs/DOM/FileReader) + - : The `FileReader` API lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using [`File`](/zh-TW/docs/DOM/File) or [`Blob`](/zh-TW/docs/DOM/Blob) objects to specify the file or data to read. File objects may be obtained from a [`FileList`](/zh-TW/docs/DOM/FileList) object returned as a result of a user selecting files using the [`">`](/en-US/docs/HTML/Element/input) element, from a drag and drop operation's [`DataTransfer`](/En/DragDrop/DataTransfer) object, or from the `mozGetAsFile()` API on an [`HTMLCanvasElement`](/zh-TW/docs/DOM/HTMLCanvasElement). +- [HTML in XMLHttpRequest](/zh-TW/docs/HTML_in_XMLHttpRequest) + - : The W3C [XMLHttpRequest](http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html) specification adds HTML parsing support to [`XMLHttpRequest`](/en/DOM/XMLHttpRequest), which originally supported only XML parsing. This feature allows Web apps to obtain an HTML resource as a parsed DOM using `XMLHttpRequest`. +- [Other resources](/zh-TW/docs/AJAX/Other_Resources) + - : Other Ajax resources you may find useful. + +## 參見 + +- [Alternate Ajax Techniques](http://www.webreference.com/programming/ajax_tech/) + - : Most articles on Ajax have focused on using XMLHttp as the means to achieving such communication, but Ajax techniques are not limited to just XMLHttp. There are several other methods. +- [Ajax: A New Approach to Web Applications](http://adaptivepath.org/ideas/ajax-new-approach-web-applications/) + - : Jesse James Garrett, of [adaptive path](http://www.adaptivepath.com), wrote this article in February 2005, introducing Ajax and its related concepts. +- [A Simpler Ajax Path](http://www.onlamp.com/pub/a/onlamp/2005/05/19/xmlhttprequest.html) + - : "As it turns out, it's pretty easy to take advantage of the XMLHttpRequest object to make a web app act more like a desktop app while still using traditional tools like web forms for collecting user input." +- [Ajax Mistakes](http://alexbosworth.backpackit.com/pub/67688) + - : Alex Bosworth has written this article outlining some of the mistakes Ajax application developers can make. +- [Tutorial](http://www.xul.fr/en-xml-ajax.html) with examples. + - : TBD +- [XMLHttpRequest specification](http://www.w3.org/TR/XMLHttpRequest/) + - : W3C Working draft + +## 社群 + +- [Ajax community links](/zh-TW/docs/AJAX/Community) + +## 工具 + +- [Toolkits and frameworks](http://www.ajaxprojects.com) +- [Firebug - Ajax/Web development tool](http://www.getfirebug.com/) +- [AJAX Debugging Tool](http://blog.monstuff.com/archives/000252.html) +- [Flash/AJAX Integration Kit](http://www.osflash.org/doku.php?id=flashjs) +- [A Simple XMLHTTP Interface Library](http://xkr.us/code/javascript/XHConn/) + +## 範例 + +- [Ajax poller script](http://www.dhtmlgoodies.com/index.html?whichScript=ajax-poller) +- [Ajax Chat Tutorial](http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=9) +- [RSS Ticker with Ajax](http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=13) +- [Create your own Ajax effects](http://www.thinkvitamin.com/features/ajax/create-your-own-ajax-effects) +- [Ajax: Creating Huge Bookmarklets](http://codinginparadise.org/weblog/2005/08/ajax-creating-huge-bookmarklets.html) +- [Ajax: Hot!Ajax There are many cool examples](http://www.hotajax.org) + +## 相關主題 + +[HTML](/zh-TW/docs/HTML), [XHTML](/zh-TW/docs/XHTML), [CSS](/zh-TW/docs/CSS), [DOM](/zh-TW/docs/DOM), [JavaScript](/zh-TW/docs/JavaScript), [XML](/zh-TW/docs/XML), [XMLHttpRequest](/zh-TW/docs/nsIXMLHttpRequest), [XSLT](/zh-TW/docs/XSLT), [DHTML](/zh-TW/docs/DHTML), [Same Origin Policy](/zh-TW/docs/JavaScript/Same_origin_policy_for_JavaScript) + +{{ListSubpages}} diff --git a/files/zh-tw/web/guide/graphics/index.html b/files/zh-tw/web/guide/graphics/index.html deleted file mode 100644 index 8e060ea1f06eb5..00000000000000 --- a/files/zh-tw/web/guide/graphics/index.html +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: 網頁上的圖像 -slug: Web/Guide/Graphics -translation_of: Web/Guide/Graphics ---- -現代網站或應用程式通常都配有圖像。我們可以很容易地使用{{HTMLElement("img")}}元素呈現靜態圖像 , 或藉由使用{{cssxref("background-image")}} 設定HTML的背景元素性質。你常會想要建立動態圖像或在事後操縱圖像。這些文章將讓你知道如何達成這些效果。
- -每個 HTML 元素都要遵從該元素可擁有何種內容規則,這些規則被歸為幾種常用的內容模型(content model)。每個 HTML 元素都屬於零個、一個、或數個內容的模型,所有元素內容的設置規則都要遵從 HTML 一致性文件。
- -內容類型有三種類型:
- -屬於元資訊內容類型的元素修飾該文件其餘部分的陳述或行為、與其他文件建立連結、或是傳達其他外來(out of band)訊息。
- -屬於這個類型的元素有 {{HTMLElement("base")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("link")}}、{{HTMLElement("meta")}}、{{HTMLElement("noscript")}}、{{HTMLElement("script")}}、{{HTMLElement("style")}} 與 {{HTMLElement("title")}}
- -屬於流內容的元素通常含有文字或嵌入內容。它們是:{{HTMLElement("a")}}、{{HTMLElement("abbr")}}、{{HTMLElement("address")}}、{{HTMLElement("article")}}、{{HTMLElement("aside")}}、{{HTMLElement("audio")}}、{{HTMLElement("b")}},{{HTMLElement("bdo")}}、{{HTMLElement("bdi")}}、{{HTMLElement("blockquote")}}、{{HTMLElement("br")}}、{{HTMLElement("button")}}、{{HTMLElement("canvas")}}、{{HTMLElement("cite")}}、{{HTMLElement("code")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("data")}}、{{HTMLElement("datalist")}}、{{HTMLElement("del")}}、{{HTMLElement("details")}}、{{HTMLElement("dfn")}}、{{HTMLElement("div")}}、{{HTMLElement("dl")}}、{{HTMLElement("em")}}、{{HTMLElement("embed")}}、{{HTMLElement("fieldset")}}、{{HTMLElement("figure")}}、{{HTMLElement("footer")}}、{{HTMLElement("form")}}、{{HTMLElement("h1")}}、{{HTMLElement("h2")}}、{{HTMLElement("h3")}}、{{HTMLElement("h4")}}、{{HTMLElement("h5")}}、{{HTMLElement("h6")}}、{{HTMLElement("header")}}、{{HTMLElement("hgroup")}}、{{HTMLElement("hr")}}、{{HTMLElement("i")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{HTMLElement("input")}}、{{HTMLElement("ins")}}、{{HTMLElement("kbd")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("main")}}、{{HTMLElement("map")}}、{{HTMLElement("mark")}}、{{MathMLElement("math")}}、{{HTMLElement("menu")}}、{{HTMLElement("meter")}}、{{HTMLElement("nav")}}、{{HTMLElement("noscript")}}、{{HTMLElement("object")}}、{{HTMLElement("ol")}}、{{HTMLElement("output")}}、{{HTMLElement("p")}}、{{HTMLElement("pre")}}、{{HTMLElement("progress")}}、{{HTMLElement("q")}}、{{HTMLElement("ruby")}}、{{HTMLElement("s")}}、{{HTMLElement("samp")}}、{{HTMLElement("script")}}、{{HTMLElement("section")}}、{{HTMLElement("select")}}、{{HTMLElement("small")}}、{{HTMLElement("span")}}、{{HTMLElement("strong")}}、{{HTMLElement("sub")}}、{{HTMLElement("sup")}}、{{SVGElement("svg")}}、{{HTMLElement("table")}}、{{HTMLElement("template")}}、{{HTMLElement("textarea")}}、{{HTMLElement("time")}}、{{HTMLElement("ul")}}、{{HTMLElement("var")}}、{{HTMLElement("video")}}、{{HTMLElement("wbr")}} 還有文字。
- -在滿足特定條件下,某些元素也屬這個類型:
- -屬於章節型內容模型的元素會在該大綱裡面創立章節,這個章節會定義{{HTMLElement("header")}}、{{HTMLElement("footer")}}、還有heading content的範圍。
- -屬於這個類型的元素有{{HTMLElement("article")}}、{{HTMLElement("aside")}}、{{HTMLElement("nav")}}還有{{HTMLElement("section")}}。
- -注意:不要把這個內容模型,和把內容與常規大綱隔開的 sectioning root 類別搞混。
-標題型內容定義了章節的標題,不論該章節由明確的章節型內容元素標記、抑或由標題本身隱式定義。
- -屬於這個類型的元素有{{HTMLElement("h1")}}、{{HTMLElement("h2")}}、{{HTMLElement("h3")}}, {{HTMLElement("h4")}}、{{HTMLElement("h5")}}、{{HTMLElement("h6")}}還有{{HTMLElement("hgroup")}}.
- -注意:儘管 {{HTMLElement("header")}} 可能含有某些標題型內容,但它本身並不是。
-段落型內容定義了文字、還有它包含的標記。Runs of phrasing content make up paragraphs.
- -屬於這個類型的元素有{{HTMLElement("abbr")}}、{{HTMLElement("audio")}}、{{HTMLElement("b")}}、{{HTMLElement("bdo")}}、{{HTMLElement("br")}}、{{HTMLElement("button")}}、{{HTMLElement("canvas")}}、{{HTMLElement("cite")}}、{{HTMLElement("code")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("datalist")}}、{{HTMLElement("dfn")}}、{{HTMLElement("em")}}、{{HTMLElement("embed")}}、{{HTMLElement("i")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{HTMLElement("input")}}、{{HTMLElement("kbd")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("mark")}}、{{MathMLElement("math")}}、{{HTMLElement("meter")}}、{{HTMLElement("noscript")}}、{{HTMLElement("object")}}、{{HTMLElement("output")}}、{{HTMLElement("progress")}}、{{HTMLElement("q")}}、{{HTMLElement("ruby")}}、{{HTMLElement("samp")}}、{{HTMLElement("script")}}、{{HTMLElement("select")}}、{{HTMLElement("small")}}、{{HTMLElement("span")}}、{{HTMLElement("strong")}}、{{HTMLElement("sub")}}、{{HTMLElement("sup")}}、{{SVGElement("svg")}}、{{HTMLElement("textarea")}}、{{HTMLElement("time")}}、{{HTMLElement("var")}}、{{HTMLElement("video")}}、{{HTMLElement("wbr")}}以及空白字符在內的純文本。
- -在滿足特定條件下,某些元素也屬這個類型:
- -嵌入型內容從其他標記語言或文件命名空間,導入資源或插入內容。 屬於這個類型的元素有{{HTMLElement("audio")}}、{{HTMLElement("canvas")}}、{{HTMLElement("embed")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{MathMLElement("math")}}、{{HTMLElement("object")}}、{{SVGElement("svg")}}、{{HTMLElement("video")}}。
- -互動型內容包含專為用戶互動設計的元素。屬於這個類型的元素有 {{HTMLElement("a")}}、{{HTMLElement("button")}}、{{HTMLElement("details")}}、{{HTMLElement("embed")}}、{{HTMLElement("iframe")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("select")}} 還有 {{HTMLElement("textarea")}}。
- -在滿足特定條件下,某些元素也屬這個類型:
- -不是空白或隱藏的內容稱為捫及。屬於流內容或是Phrasing content模型的元素最少要有一個捫及的節點。
- -表單相關內容包含了由 form 屬性顯露的 form owner 元素。form owner 是本身包含於 {{HTMLElement("form")}}、或 id 由 form 屬性指定的元素。
- -本類型包含某些子類別:
- -如果一個元素是透明內容模型,then its contents must be structured such that they would be valid HTML 5,就算該透明元素被移除、並由子元素取代。
- -例如,{{HTMLElement("del")}} 與 {{HTMLELement("ins")}} 元素都是透明的:
- -<p>我們認為下面這些真理是<del><em>神聖不可否認</em></del><ins>不言而喻的。</ins></p> -- -
這果這些元素被刪掉的話,這個分段依然在 HTML 有效(if not correct English)
- -<p>我們認為下面這些真理是<em>神聖不可否認</em>不言而喻的。</p> -- - -
章節根(Sectioning root)
diff --git a/files/zh-tw/web/guide/html/content_categories/index.md b/files/zh-tw/web/guide/html/content_categories/index.md new file mode 100644 index 00000000000000..a16b3308cc5341 --- /dev/null +++ b/files/zh-tw/web/guide/html/content_categories/index.md @@ -0,0 +1,133 @@ +--- +title: 內容類型 +slug: Web/Guide/HTML/Content_categories +translation_of: Web/Guide/HTML/Content_categories +--- +每個 HTML 元素都要遵從該元素可擁有何種內容規則,這些規則被歸為幾種常用的內容模型(content model)。每個 HTML 元素都屬於零個、一個、或數個內容的模型,所有元素內容的設置規則都要遵從 HTML 一致性文件。 + +內容類型有三種類型: + +- 主要內容類型(Main content categories)描述了許多元素共享的常見內容規則(content rule)。 +- 表單相關內容類型(Form-related content categories)描述了表單相關元素的內容規則。 +- 特別內容類型(Specific content categories) 描述了只有少數元素共享的內容規則,有時甚至只有特定上下文。 + +![Content_categories_venn.png](content_categories_venn.png) + +## 主要內容類型 + +### 資訊元內容(Metadata content) + +屬於*元資訊內容*類型的元素修飾該文件其餘部分的陳述或行為、與其他文件建立連結、或是傳達其他*外來*(out of band)訊息。 + +屬於這個類型的元素有 {{HTMLElement("base")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("link")}}、{{HTMLElement("meta")}}、{{HTMLElement("noscript")}}、{{HTMLElement("script")}}、{{HTMLElement("style")}} 與 {{HTMLElement("title")}} + +### 流內容(Flow content) + +屬於流內容的元素通常含有文字或嵌入內容。它們是:{{HTMLElement("a")}}、{{HTMLElement("abbr")}}、{{HTMLElement("address")}}、{{HTMLElement("article")}}、{{HTMLElement("aside")}}、{{HTMLElement("audio")}}、{{HTMLElement("b")}},{{HTMLElement("bdo")}}、{{HTMLElement("bdi")}}、{{HTMLElement("blockquote")}}、{{HTMLElement("br")}}、{{HTMLElement("button")}}、{{HTMLElement("canvas")}}、{{HTMLElement("cite")}}、{{HTMLElement("code")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("data")}}、{{HTMLElement("datalist")}}、{{HTMLElement("del")}}、{{HTMLElement("details")}}、{{HTMLElement("dfn")}}、{{HTMLElement("div")}}、{{HTMLElement("dl")}}、{{HTMLElement("em")}}、{{HTMLElement("embed")}}、{{HTMLElement("fieldset")}}、{{HTMLElement("figure")}}、{{HTMLElement("footer")}}、{{HTMLElement("form")}}、{{HTMLElement("h1")}}、{{HTMLElement("h2")}}、{{HTMLElement("h3")}}、{{HTMLElement("h4")}}、{{HTMLElement("h5")}}、{{HTMLElement("h6")}}、{{HTMLElement("header")}}、{{HTMLElement("hgroup")}}、{{HTMLElement("hr")}}、{{HTMLElement("i")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{HTMLElement("input")}}、{{HTMLElement("ins")}}、{{HTMLElement("kbd")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("main")}}、{{HTMLElement("map")}}、{{HTMLElement("mark")}}、{{MathMLElement("math")}}、{{HTMLElement("menu")}}、{{HTMLElement("meter")}}、{{HTMLElement("nav")}}、{{HTMLElement("noscript")}}、{{HTMLElement("object")}}、{{HTMLElement("ol")}}、{{HTMLElement("output")}}、{{HTMLElement("p")}}、{{HTMLElement("pre")}}、{{HTMLElement("progress")}}、{{HTMLElement("q")}}、{{HTMLElement("ruby")}}、{{HTMLElement("s")}}、{{HTMLElement("samp")}}、{{HTMLElement("script")}}、{{HTMLElement("section")}}、{{HTMLElement("select")}}、{{HTMLElement("small")}}、{{HTMLElement("span")}}、{{HTMLElement("strong")}}、{{HTMLElement("sub")}}、{{HTMLElement("sup")}}、{{SVGElement("svg")}}、{{HTMLElement("table")}}、{{HTMLElement("template")}}、{{HTMLElement("textarea")}}、{{HTMLElement("time")}}、{{HTMLElement("ul")}}、{{HTMLElement("var")}}、{{HTMLElement("video")}}、{{HTMLElement("wbr")}} 還有文字。 + +在滿足特定條件下,某些元素也屬這個類型: + +- {{HTMLElement("area")}},如果它是 {{HTMLElement("map")}} 元素的後代。 +- {{HTMLElement("link")}},如果[**itemprop**](/zh-TW/docs/HTML/Global_attributes#attr-itemprop) 屬性存在。 +- {{HTMLElement("meta")}},如果[**itemprop**](/zh-TW/docs/HTML/Global_attributes#attr-itemprop) 屬性存在。 +- {{HTMLElement("style")}},如果 {{htmlattrxref("scoped","style")}} 屬性存在。 + +### 章節型內容(Sectioning content) + +屬於章節型內容模型的元素會[在該大綱裡面創立章節](/zh-TW/docs/Sections_and_Outlines_of_an_HTML5_document),這個章節會定義{{HTMLElement("header")}}、{{HTMLElement("footer")}}、還有[heading content](#Heading_content)的範圍。 + +屬於這個類型的元素有{{HTMLElement("article")}}、{{HTMLElement("aside")}}、{{HTMLElement("nav")}}還有{{HTMLElement("section")}}。 + +> **備註:** 不要把這個內容模型,和把內容與常規大綱隔開的 [sectioning root](/zh-TW/docs/Sections_and_Outlines_of_an_HTML5_document#sectioning_root) 類別搞混。 + +### 標題型內容(Heading content) + +標題型內容定義了章節的標題,不論該章節由明確的[章節型內容](#Sectioning_content)元素標記、抑或由標題本身隱式定義。 + +屬於這個類型的元素有{{HTMLElement("h1")}}、{{HTMLElement("h2")}}、{{HTMLElement("h3")}}, {{HTMLElement("h4")}}、{{HTMLElement("h5")}}、{{HTMLElement("h6")}}還有{{HTMLElement("hgroup")}}. + +> **備註:** 儘管 {{HTMLElement("header")}} 可能含有某些標題型內容,但它本身並不是。 + +### 段落型內容(Phrasing content) + +段落型內容定義了文字、還有它包含的標記。Runs of phrasing content make up paragraphs. + +屬於這個類型的元素有{{HTMLElement("abbr")}}、{{HTMLElement("audio")}}、{{HTMLElement("b")}}、{{HTMLElement("bdo")}}、{{HTMLElement("br")}}、{{HTMLElement("button")}}、{{HTMLElement("canvas")}}、{{HTMLElement("cite")}}、{{HTMLElement("code")}}、{{Deprecated_Inline}}{{HTMLElement("command")}}、{{HTMLElement("datalist")}}、{{HTMLElement("dfn")}}、{{HTMLElement("em")}}、{{HTMLElement("embed")}}、{{HTMLElement("i")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{HTMLElement("input")}}、{{HTMLElement("kbd")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("mark")}}、{{MathMLElement("math")}}、{{HTMLElement("meter")}}、{{HTMLElement("noscript")}}、{{HTMLElement("object")}}、{{HTMLElement("output")}}、{{HTMLElement("progress")}}、{{HTMLElement("q")}}、{{HTMLElement("ruby")}}、{{HTMLElement("samp")}}、{{HTMLElement("script")}}、{{HTMLElement("select")}}、{{HTMLElement("small")}}、{{HTMLElement("span")}}、{{HTMLElement("strong")}}、{{HTMLElement("sub")}}、{{HTMLElement("sup")}}、{{SVGElement("svg")}}、{{HTMLElement("textarea")}}、{{HTMLElement("time")}}、{{HTMLElement("var")}}、{{HTMLElement("video")}}、{{HTMLElement("wbr")}}以及空白字符在內的純文本。 + +在滿足特定條件下,某些元素也屬這個類型: + +- {{HTMLElement("a")}},如果它只包含段落型內容。 +- {{HTMLElement("area")}},如果它是 {{HTMLElement("map")}} 元素的後代。 +- {{HTMLElement("del")}},如果它只包含段落型內容。 +- {{HTMLElement("ins")}}, 如果它只包含段落型內容。 +- {{HTMLElement("link")}}, 如果 [**itemprop**](/zh-TW/docs/HTML/Global_attributes#itemprop) 屬性存在。 +- {{HTMLElement("map")}}, 如果它只包含段落型內容。 +- {{HTMLElement("meta")}}, 如果 [**itemprop**](/zh-TW/docs/HTML/Global_attributes#itemprop) 屬性存在。 + +### 嵌入型內容(Embedded content) + +嵌入型內容從其他標記語言或文件命名空間,導入資源或插入內容。 屬於這個類型的元素有{{HTMLElement("audio")}}、{{HTMLElement("canvas")}}、{{HTMLElement("embed")}}、{{HTMLElement("iframe")}}、{{HTMLElement("img")}}、{{MathMLElement("math")}}、{{HTMLElement("object")}}、{{SVGElement("svg")}}、{{HTMLElement("video")}}。 + +### 互動型內容(Interactive content) + +互動型內容包含專為用戶互動設計的元素。屬於這個類型的元素有 {{HTMLElement("a")}}、{{HTMLElement("button")}}、{{HTMLElement("details")}}、{{HTMLElement("embed")}}、{{HTMLElement("iframe")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("label")}}、{{HTMLElement("select")}} 還有 {{HTMLElement("textarea")}}。 + +在滿足特定條件下,某些元素也屬這個類型: + +- {{HTMLElement("audio")}},如果 {{htmlattrxref("controls", "audio")}} 元素存在。 +- {{HTMLElement("img")}},如果 {{htmlattrxref("usemap", "img")}} 元素存在。 +- {{HTMLElement("input")}},如果 {{htmlattrxref("type", "input")}} 元素不是隱藏狀態。 +- {{HTMLElement("menu")}},如果 {{htmlattrxref("type", "menu")}} 元素處於 toolbar 狀態。 +- {{HTMLElement("object")}},如果 {{htmlattrxref("usemap", "object")}} 元素存在。 +- {{HTMLElement("video")}},如果 {{htmlattrxref("controls", "video")}} 元素存在。 + +### 捫及內容(Palpable content) + +不是空白或隱藏的內容稱為捫及。屬於流內容或是 Phrasing content 模型的元素最少要有一個捫及的節點。 + +### 表單相關內容(Form-associated content) + +表單相關內容包含了由 **form** 屬性顯露的 form owner 元素。form owner 是本身包含於 {{HTMLElement("form")}}、或 id 由 **form** 屬性指定的元素。 + +- {{HTMLElement("button")}} +- {{HTMLElement("fieldset")}} +- {{HTMLElement("input")}} +- {{deprecated_inline()}}{{HTMLElement("keygen")}} +- {{HTMLElement("label")}} +- {{HTMLElement("meter")}} +- {{HTMLElement("object")}} +- {{HTMLElement("output")}} +- {{HTMLElement("progress")}} +- {{HTMLElement("select")}} +- {{HTMLElement("textarea")}} + +本類型包含某些子類別: + +- listed + - : Elements that are listed in the [form.elements](/zh-TW/docs/DOM/form.elements) and fieldset.elements IDL collections. Contains {{HTMLElement("button")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}}, {{deprecated_inline()}}{{HTMLElement("keygen")}}, {{HTMLElement("object")}}, {{HTMLElement("output")}}, {{HTMLElement("select")}}, and {{HTMLElement("textarea")}}. +- labelable + - : 與元素 {{HTMLElement("label")}} 相關的元素。包含 {{HTMLElement("button")}}、{{HTMLElement("input")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("meter")}}、{{HTMLElement("output")}}、{{HTMLElement("progress")}}、{{HTMLElement("select")}}、{{HTMLElement("textarea")}}。 +- submittable + - : 用在建構送出時,資料就設定好的表單元素。包含 {{HTMLElement("button")}}、{{HTMLElement("input")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("object")}}、{{HTMLElement("select")}}、{{HTMLElement("textarea")}}。 +- resettable + - : 當表單重設時會受影響的元素。包含 {{HTMLElement("button")}}、{{HTMLElement("input")}}、{{deprecated_inline()}}{{HTMLElement("keygen")}}、{{HTMLElement("output")}}、{{HTMLElement("select")}}、{{HTMLElement("textarea")}}。 + +## 透明內容模型(Transparent content model) + +如果一個元素是透明內容模型,then its contents must be structured such that they would be valid HTML 5,就算該透明元素被移除、並由子元素取代。 + +例如,{{HTMLElement("del")}} 與 {{HTMLELement("ins")}} 元素都是透明的: + +```plain +我們認為下面這些真理是神聖不可否認不言而喻的。
我們認為下面這些真理是神聖不可否認不言而喻的。
+``` + +## 其他內容模型 + +章節根(Sectioning root) diff --git a/files/zh-tw/web/guide/index.html b/files/zh-tw/web/guide/index.html deleted file mode 100644 index 2b46129d510fde..00000000000000 --- a/files/zh-tw/web/guide/index.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: Web 開發者指引 -slug: Web/Guide -tags: - - Guide - - Landing - - NeedsTranslation - - TopicStub - - Web -translation_of: Web/Guide ---- -這些文章提供了如何幫助你使用特定技術和 APIs 的資訊。
- -注意: 很抱歉。這個頁面在我們完成內容遷移之前會很混亂。
-不論你是否是剛入門的 Web 開發者,或者只是為了拓寬視野而進入全新的 Web 領域,這裡的連結應該幫得上你。至少,我們在此有很多的連結。
- 文件主題在此我們還沒有任何文章,但很需要。 | 資源- |
HTML 中的元素具有屬性 ; 而這些屬性可以藉由各種方式去設定元素或調整它們的行為,以符合使用者的期待。
- -屬性名稱 | -元素 | -描述 | -
---|---|---|
hidden |
- Global attribute | -避免呈現給定的元素,並且保持子元素,例如 script elements、active。 | -
high |
- {{ HTMLElement("meter") }} | -指示下界的上限範圍。 | -
href |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }}, {{ HTMLElement("base") }}, {{ HTMLElement("link") }} | -連結資源的 URL。 | -
hreflang |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }}, {{ HTMLElement("link") }} | -指定連結資源的語言。 | -
http-equiv |
- {{ HTMLElement("meta") }} | -- |
icon |
- {{ HTMLElement("command") }} | -指定呈現指令的圖片。 | -
id |
- Global attribute | -經常和 CSS 一起被用來設計特定元素。這個屬性的值必須是唯一的。 | -
ismap |
- {{ HTMLElement("img") }} | -指示該圖像是伺服器端之影像地圖的一部分。 | -
itemprop |
- Global attribute | -- |
keytype |
- {{ HTMLElement("keygen") }} | -指定所生成密鑰的類型。 | -
kind |
- {{ HTMLElement("track") }} | -指明文章 track 的類型。 | -
label |
- {{ HTMLElement("track") }} | -指明文章 track 的使用者可讀之標題。 | -
lang |
- Global attribute | -定義該元素中所使用的語言。 | -
language |
- {{ HTMLElement("script") }} | -定義該元素中所使用的腳本語言。 | -
list |
- {{ HTMLElement("input") }} | -指示一串預先定義的選項供使用者參考。 | -
loop |
- {{ HTMLElement("audio") }}, {{ HTMLElement("bgsound") }}, {{ HTMLElement("marquee") }}, {{ HTMLElement("video") }} | -指示當媒體完成時,是否應該從一開始的時候播放。 | -
low |
- {{ HTMLElement("meter") }} | -指示上界的下限範圍。 | -
manifest |
- {{ HTMLElement("html") }} | -指定文件中緩存清單的 URL。 | -
max |
- {{ HTMLElement("input") }}, {{ HTMLElement("meter") }}, {{ HTMLElement("progress") }} | -指示所允許的最大值。 | -
maxlength |
- {{ HTMLElement("input") }}, {{ HTMLElement("textarea") }} | -定義該元素中所允許的最大字元數目。 | -
media |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }}, {{ HTMLElement("link") }}, {{ HTMLElement("source") }}, {{ HTMLElement("style") }} | -指定一些連接資源已經被設計的媒體。 | -
method |
- {{ HTMLElement("form") }} | -定義當呈交該格式時,哪個 HTTP 方法要被使用。可以用 GET(預設)或是 POST。 | -
min |
- {{ HTMLElement("input") }}, {{ HTMLElement("meter") }} | -指示所允許的最小值。 | -
multiple |
- {{ HTMLElement("input") }}, {{ HTMLElement("select") }} | -指示多個值是否可以進入單一輸入的 email 或是 file 之類別。 |
-
name |
- {{ HTMLElement("button") }}, {{ HTMLElement("form") }}, {{ HTMLElement("fieldset") }}, {{ HTMLElement("iframe") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("object") }}, {{ HTMLElement("output") }}, {{ HTMLElement("select") }}, {{ HTMLElement("textarea") }}, {{ HTMLElement("map") }}, {{ HTMLElement("meta") }}, {{ HTMLElement("param") }} | -
- 元素的名字。例如被伺服器所使用時,來識別格式提交的現場。 - |
-
novalidate |
- {{ HTMLElement("form") }} | -該屬性指示當本格式被提交時,並無法通過驗證。 | -
open |
- {{ HTMLElement("details") }} | -指示是否細節顯示於加載頁面上。 | -
optimum |
- {{ HTMLElement("meter") }} | -指示最佳化數值。 | -
pattern |
- {{ HTMLElement("input") }} | -定義一個元素值將被驗證的正規表達式。 | -
ping |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }} | -- |
placeholder |
- {{ HTMLElement("input") }}, {{ HTMLElement("textarea") }} | -提示使用者什麼可以被輸入進該區。 | -
poster |
- {{ HTMLElement("video") }} | -
- 顯現一個指示 poster frame 的 URL,直到使用者撥放或是搜索。 - |
-
preload |
- {{ HTMLElement("audio") }}, {{ HTMLElement("video") }} | -指示是否整個資源、一部分的資源、或是沒有資源應該被預先裝載。 | -
pubdate |
- {{ HTMLElement("time") }} | -指示該日期和時間,是否和距離最近的 {{ HTMLElement("article") }} 舊元素的日期一樣。 | -
radiogroup |
- {{ HTMLElement("command") }} | -- |
readonly |
- {{ HTMLElement("input") }}, {{ HTMLElement("textarea") }} | -指示是否該元素可以被編輯。 | -
rel |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }}, {{ HTMLElement("link") }} | -指定目標物件和連結物驗的關係。 | -
required |
- {{ HTMLElement("input") }}, {{ HTMLElement("select") }}, {{ HTMLElement("textarea") }} | -指示該元素是否被要求填寫。 | -
reversed |
- {{ HTMLElement("ol") }} | -指示該目錄是否應以降序展出而不是升序。 | -
rows |
- {{ HTMLElement("textarea") }} | -定義 textarea 的行數。 | -
rowspan |
- {{ HTMLElement("td") }}, {{ HTMLElement("th") }} | -定義表格單元的行數應該被 span over。 | -
sandbox |
- {{ HTMLElement("iframe") }} | -- |
spellcheck |
- Global attribute | -指示為該元素的拼字檢查是否允許。 | -
scope |
- {{ HTMLElement("th") }} | -- |
scoped |
- {{ HTMLElement("style") }} | -- |
seamless |
- {{ HTMLElement("iframe") }} | -- |
selected |
- {{ HTMLElement("option") }} | -定義一個值將被選擇到上載頁面中。 | -
shape |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }} | -- |
size |
- {{ HTMLElement("input") }}, {{ HTMLElement("select") }} | -定義元素的寬度 (以 pixel 為單位) 。如果該元素之類型的屬性是文本或是密碼,那麼它就是字元的數目。 | -
sizes |
- {{ HTMLElement("link") }} | -- |
span |
- {{ HTMLElement("col") }}, {{ HTMLElement("colgroup") }} | -- |
src |
- {{ HTMLElement("audio") }}, {{ HTMLElement("embed") }}, {{ HTMLElement("iframe") }}, {{ HTMLElement("img") }}, {{ HTMLElement("input") }}, {{ HTMLElement("script") }}, {{ HTMLElement("source") }}, {{ HTMLElement("track") }}, {{ HTMLElement("video") }} | -可嵌入內容的網址。 | -
srcdoc |
- {{ HTMLElement("iframe") }} | -- |
srclang |
- {{ HTMLElement("track") }} | -- |
srcset |
- {{ HTMLElement("img") }} | -- |
start |
- {{ HTMLElement("ol") }} | -如果第一個數字不是 1 的話,則定義該數。 | -
step |
- {{ HTMLElement("input") }} | -- |
style |
- Global attribute | -定義多載先前的樣式設定之 CSS 樣式。 | -
summary |
- {{ HTMLElement("table") }} | -- |
tabindex |
- Global attribute | -多載瀏覽器的預設頁面標籤之順序並且遵守指定的那個。 | -
target |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }}, {{ HTMLElement("base") }}, {{ HTMLElement("form") }} | -- |
title |
- Global attribute | -當滑鼠標停在元素時,文本會顯示在工具提示中。 | -
type |
- {{ HTMLElement("button") }}, {{ HTMLElement("input") }}, {{ HTMLElement("command") }}, {{ HTMLElement("embed") }}, {{ HTMLElement("object") }}, {{ HTMLElement("script") }}, {{ HTMLElement("source") }}, {{ HTMLElement("style") }}, {{ HTMLElement("menu") }} | -定義元素的類型。 | -
usemap |
- {{ HTMLElement("img") }}, {{ HTMLElement("input") }}, {{ HTMLElement("object") }} | -- |
value |
- {{ HTMLElement("button") }}, {{ HTMLElement("option") }}, {{ HTMLElement("input") }}, {{ HTMLElement("li") }}, {{ HTMLElement("meter") }}, {{ HTMLElement("progress") }}, {{ HTMLElement("param") }} | -定義將顯示在加載頁面上元素的預設值。 | -
width |
- {{ HTMLElement("canvas") }}, {{ HTMLElement("embed") }}, {{ HTMLElement("iframe") }}, {{ HTMLElement("img") }}, {{ HTMLElement("input") }}, {{ HTMLElement("object") }}, {{ HTMLElement("video") }} | -注意 : 在有些情況中,例如 {{ HTMLElement("div") }},這是傳統的屬性,而 CSS {{ Cssxref("width") }} 特性應當被使用。在其他的情況中,例如 {{ HTMLElement("canvas") }} ,寬度必須用該屬性來指定。 | -
wrap |
- {{ HTMLElement("textarea") }} | -指定文章是否要被掩飾。 | -
border |
- {{ HTMLElement("img") }}, {{ HTMLElement("object") }}, {{ HTMLElement("table") }} | -
- 邊界寬度。 - -注意 : 這是一個傳統的屬性。請利用 CSS {{ Cssxref("border") }} 特性。 - |
-
buffered |
- {{ HTMLElement("audio") }}, {{ HTMLElement("video") }} | -包含被緩衝之媒體的時間範圍。 | -
challenge |
- {{ HTMLElement("keygen") }} | -隨著公共密鑰提交的挑戰字串。 | -
charset |
- {{ HTMLElement("meta") }}, {{ HTMLElement("script") }} | -聲明頁面或腳本的字元編碼。 | -
checked |
- {{ HTMLElement("command") }}, {{ HTMLElement("input") }} | -指定在加載頁面上的元素是否要被檢查。 | -
cite |
- {{ HTMLElement("blockquote") }}, {{ HTMLElement("del") }}, {{ HTMLElement("ins") }}, {{ HTMLElement("q") }} | -包含一個 URL,用來指出引用或是改變的來源地址。 | -
class |
- Global attribute | -經常使用共同屬性和 CSS 一起設計元素。 | -
code |
- {{ HTMLElement("applet") }} | -指明被加載與執行的 applet 類別文件之 URL。 | -
codebase |
- {{ HTMLElement("applet") }} | -This attribute gives the absolute or relative URL of the directory where applets' .class files referenced by the code attribute are stored. | -
color |
- {{ HTMLElement("basefont") }}, {{ HTMLElement("font") }}, {{ HTMLElement("hr") }} | -
- 該屬性使用命名顏色或十六進制 #RRGGBB 格式來設置文本顏色。 - -注意 : 這是一個傳統的屬性。請使用 CSS {{ Cssxref("color") }} 特性。 - |
-
cols |
- {{ HTMLElement("textarea") }} | -定義在一個 textarea 中有多少欄位。 | -
colspan |
- {{ HTMLElement("td") }}, {{ HTMLElement("th") }} | -colspan 屬性定義一個單元格之欄位的數量。 | -
content |
- {{ HTMLElement("meta") }} | -一個有關於 http-equiv 或是根據上下文 name 的值 。 |
-
contenteditable |
- Global attribute | -指定元素的內容是否可以被編輯。 | -
contextmenu |
- Global attribute | -定義將作為元素上下文選項單的 {{ HTMLElement("menu") }} 元素之 ID。 | -
controls |
- {{ HTMLElement("audio") }}, {{ HTMLElement("video") }} | -指定瀏覽器是否應該顯示錄放控制給使用者。 | -
coords |
- {{ HTMLElement("area") }} | -一組值指明熱點區域的座標。 | -
-
|
-
- {{ HTMLElement("object") }} - |
-
- 指明 URL 的資源。 - |
-
-
|
- - - | -
- 讓您可以將自行定義屬性附加在 HTML 元素上。 - |
-
datetime |
- {{ HTMLElement("del") }}, {{ HTMLElement("ins") }}, {{ HTMLElement("time") }} | -指定元素所相關的日期與時間。 | -
default |
- {{ HTMLElement("track") }} | -指定 track 應被啟用,除非使用者的偏好表示不同。 | -
defer |
- {{ HTMLElement("script") }} | -指定該頁面被瀏覽完後腳本應被執行。 | -
dir |
- Global attribute | -定義文章的方向。被允許的值有 ltr (Left-To-Right) 或 rtl (Right-To-Left)。 | -
dirname |
- {{ HTMLElement("input") }}, {{ HTMLElement("textarea") }} | -- |
disabled |
- {{ HTMLElement("button") }}, {{ HTMLElement("command") }}, {{ HTMLElement("fieldset") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("optgroup") }}, {{ HTMLElement("option") }}, {{ HTMLElement("select") }}, {{ HTMLElement("textarea") }} | -指名使用者是否可以與元素互動。 | -
download |
- {{ HTMLElement("a") }}, {{ HTMLElement("area") }} | -
- 指定該超連結是用於下載的資源。 - |
-
draggable |
- Global attribute | -定義元素是否可以拖曳。 | -
dropzone |
- Global attribute | -指定該元素接受它內容的滑鼠落下物。 | -
enctype |
- {{ HTMLElement("form") }} | -當方法為 POST 的時候,定義格式日期的內容類型。 | -
for |
- {{ HTMLElement("label") }}, {{ HTMLElement("output") }} | -描述屬於這一個的元素。 | -
form |
- {{ HTMLElement("button") }}, {{ HTMLElement("fieldset") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("label") }}, {{ HTMLElement("meter") }}, {{ HTMLElement("object") }}, {{ HTMLElement("output") }}, {{ HTMLElement("progress") }}, {{ HTMLElement("select") }}, {{ HTMLElement("textarea") }} | -
- 指定元素之所有者的格式。 - |
-
formaction |
- {{ HTMLElement("input") }}, {{ HTMLElement("button") }} | -指定元素的作用,多載的動作被定義在 {{ HTMLElement("form") }}。 | -
headers |
- {{ HTMLElement("td") }}, {{ HTMLElement("th") }} | -對適用於該元素的 <th> 元素之 ID。 | -
height |
- {{ HTMLElement("canvas") }}, {{ HTMLElement("embed") }}, {{ HTMLElement("iframe") }}, {{ HTMLElement("img") }}, {{ HTMLElement("input") }}, {{ HTMLElement("object") }}, {{ HTMLElement("video") }} | -注意 : 在有些情況中,例如 {{ HTMLElement("div") }},這是傳統的屬性,而 CSS {{ Cssxref("height") }} 特性應當被使用。在其他的情況中,例如 {{ HTMLElement("canvas") }},高度必須用該屬性來指定。 | -
accept |
- {{ HTMLElement("form") }}, {{ HTMLElement("input") }} | -伺服器接受的類型之列表,通常是文件類型。 | -
accept-charset |
- {{ HTMLElement("form") }} | -支持字元集的列表。 | -
accesskey |
- Global attribute | -定義鍵盤快捷鍵來啟動或添加焦點到該元素。 | -
action |
- {{ HTMLElement("form") }} | -一個程序處理經由該格式提交信息的 URI。 | -
align |
- {{ HTMLElement("applet") }}, {{ HTMLElement("caption") }}, {{ HTMLElement("col") }}, {{ HTMLElement("colgroup") }}, {{ HTMLElement("hr") }}, {{ HTMLElement("iframe") }}, {{ HTMLElement("img") }}, {{ HTMLElement("table") }}, {{ HTMLElement("tbody") }}, {{ HTMLElement("td") }}, {{ HTMLElement("tfoot") }} , {{ HTMLElement("th") }}, {{ HTMLElement("thead") }}, {{ HTMLElement("tr") }} | -指定元素的水平對齊方式。 | -
alt |
-
- {{ HTMLElement("applet") }}, {{ HTMLElement("area") }}, {{ HTMLElement("img") }}, {{ HTMLElement("input") }} - |
- 在圖像無法顯示的情況下,顯示代替文本。 | -
async |
- {{ HTMLElement("script") }} | -指定該腳本應該被不同步得執行。 | -
autocomplete |
- {{ HTMLElement("form") }}, {{ HTMLElement("input") }} | -指定是否以該格式控制,可以在默認情況下由瀏覽器自動完成其值。 | -
autofocus |
- {{ HTMLElement("button") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("select") }}, {{ HTMLElement("textarea") }} | -該元素應該在頁面加載後自動焦距。 | -
autoplay |
- {{ HTMLElement("audio") }}, {{ HTMLElement("video") }} | -音頻或視頻應該越早撥放越好。 | -
autosave |
- {{ HTMLElement("input") }} | -上一個值應該持續存在到跨頁面加載的可選值之下拉列表中。 | -
bgcolor |
- {{ HTMLElement("body") }}, {{ HTMLElement("col") }}, {{ HTMLElement("colgroup") }}, {{ HTMLElement("marquee") }}, {{ HTMLElement("table") }}, {{ HTMLElement("tbody") }}, {{ HTMLElement("tfoot") }}, {{ HTMLElement("td") }}, {{ HTMLElement("th") }}, {{ HTMLElement("tr") }} | -
- 元素的背景顏色。 - -注意 : 這是一個傳統的屬性。請使用 CSS {{ Cssxref("background-color") }} 特性。 - |
-
在 HTML 中,大部分的屬性有兩種面向 : 內容屬性與 IDL 屬性。
- -內容屬性是您可以從內容中設定的屬性 (HTML 程式碼) 而且您可以藉由 {{domxref("element.setAttribute()")}} 或是 {{domxref("element.getAttribute()")}} 來設定它或得到它。內容屬性永遠都是字串,即便我們所期望的值是一個整數。舉例來說,假設今天要用內容屬性去設定一個 {{HTMLElement("input")}} 元素的最大長度是42,您必須在該元素上呼叫 setAttribute("maxlength", "42")。
- -IDL 屬性也被稱為 JavaScript 特性。您可以使用 JavaScript 特性的 element.foo 以閱讀或是設定這些屬性。當您要得到 IDL 屬性時,它總是要使用 (但可能改變) 基本的內容屬性以返回值,而當您要設定 IDL 屬性時,它需要儲存資料在內容屬性中。換句話說,IDL 屬性在本質上反映了內容屬性。
- -在大部分的時間中,當 IDL 屬性真正被使用時,將會返回它們的值。舉例而言,{{HTMLElement("input")}} 元素的預設型態是 "text",所以如果您設定 input.type="foobar",<input> 元素一樣是 text 的型態 (在外觀和行為上而言),但是 "type" 內容屬性的值將會變成 "foobar"。然而,IDL 屬性的型態將會回傳 "text" 字串。
- -IDL 屬性並非永遠的字串 ; 舉例來說,input.maxlength 便是一個數字(型態為 signed long)。當使用 IDL 屬性,您會閱讀或是設定所需的型態,而當您設定 input.maxlength 時,它總是回傳一個數字,因為它正需要一個數字。如果您傳入別的型態,它會依照標準 JavaScript 型態轉換規則,將傳入值轉成一個數字。
- -IDL 屬性可以 反應其他型態,例如 unsigned long、URLs、booleans,等等。不幸的是,並沒有明確的規則來規範,而且與 IDL 屬性行為相對應的內容屬性連結中,也沒有取決於該屬性的方式。在大部分的時間裡,它會遵守 規範中所制定的規則,但有時候它並不會。HTML 規範嘗試讓它變得容易使用,但由於各種原因 (大多是因為歷史),有些屬性表現得很奇怪 (舉例來說,select.size),而您應該詳細閱讀規範以了解各個屬性的行為。
- -HTML (超文字標記語言, Hypertext Markup Language) 元素通常為 "區塊級" 元素或是 "行內" 元素。 一個區塊級元素會藉由建立"區塊"的動作, 完全佔滿其父元素(容器)的空間。本文將為您說明其意涵.
- -瀏覽器預設以在元素前後換行的方式, 表現區塊級元素. 視覺上會呈現為一排縱向堆疊的方塊。
- -區塊級元素必定以換行方式, 取得完整寬度的空間(向左右兩側儘可能地延伸出去)。
-以下範例將展示區塊級元素的影響:
- -<p>This paragraph is a block-level element; its background has been colored to display the paragraph's parent element.</p>- -
p { background-color: #8ABB55; } -- -
{{ EmbedLiveSample('Block-level_Example') }}
- -There are a couple of key differences between block-level elements and inline elements:
- -The distinction of block-level vs. inline elements is used in HTML specifications up to 4.01. In HTML5, this binary distinction is replaced with a more complex set of content categories. The "block-level" category roughly corresponds to the category of flow content in HTML5, while "inline" corresponds to phrasing content, but there are additional categories.
- -The following is a complete list of all HTML block level elements (although "block-level" is not technically defined for elements that are new in HTML5).
- -This paragraph is a block-level element; its background has been colored to display the paragraph's parent element.
+``` + +### CSS + +```css +p { background-color: #8ABB55; } +``` + +{{ EmbedLiveSample('Block-level_Example') }} + +## 用法 + +- 區塊級元素只能出現於 {{ HTMLElement("body") }} 元素之內. + +## 區塊級 vs. 行內元素 + +There are a couple of key differences between block-level elements and inline elements: + +- Formatting + - : By default, block-level elements begin on new lines, but inline elements can start anywhere in a line. +- Content model + - : Generally, block-level elements may contain inline elements and other block-level elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements. + +The distinction of block-level vs. inline elements is used in HTML specifications up to 4.01. In HTML5, this binary distinction is replaced with a more complex set of [content categories](/zh-TW/docs/HTML/Content_categories). The "block-level" category roughly corresponds to the category of [flow content](/zh-TW/docs/HTML/Content_categories#Flow_content) in HTML5, while "inline" corresponds to [phrasing content](/zh-TW/docs/HTML/Content_categories#Phrasing_content), but there are additional categories. + +## 相關元素 + +The following is a complete list of all HTML block level elements (although "block-level" is not technically defined for elements that are new in HTML5). + +- {{ HTMLElement("address") }} + - : Contact information. +- {{ HTMLElement("article") }} + - : Article content. +- {{ HTMLElement("aside") }} + - : Aside content. +- {{ HTMLElement("blockquote") }} + - : Long ("block") quotation. +- {{ HTMLElement("dialog") }} + - : Dialog box. +- {{ HTMLElement("dd") }} + - : Describes a term in a description list. +- {{ HTMLElement("div") }} + - : Document division. +- {{ HTMLElement("dl") }} + - : Description list. +- {{ HTMLElement("dt") }} + - : Description list term. +- {{ HTMLElement("fieldset") }} + - : Field set label. +- {{ HTMLElement("figcaption") }} + - : Figure caption. +- {{ HTMLElement("figure") }} + - : Groups media content with a caption (see {{ HTMLElement("figcaption") }}). +- {{ HTMLElement("footer") }} + - : Section or page footer. +- {{ HTMLElement("form") }} + - : Input form. +- {{ HTMLElement("h1") }}, {{ HTMLElement("h2") }}, {{ HTMLElement("h3") }}, {{ HTMLElement("h4") }}, {{ HTMLElement("h5") }}, {{ HTMLElement("h6") }} + - : Heading levels 1-6. +- {{ HTMLElement("header") }} + - : Section or page header. +- {{ HTMLElement("hgroup") }} + - : Groups header information. +- {{ HTMLElement("hr") }} + - : Horizontal rule (dividing line). +- {{ HTMLElement("li") }} + - : List item. +- {{ HTMLElement("main") }} + - : Contains the central content unique to this document. +- {{ HTMLElement("nav") }} + - : Contains navigation links. +- {{ HTMLElement("ol") }} + - : Ordered list. +- {{ HTMLElement("p") }} + - : Paragraph. +- {{ HTMLElement("pre") }} + - : Preformatted text. +- {{ HTMLElement("section") }} + - : Section of a web page. +- {{ HTMLElement("table") }} + - : Table. +- {{ HTMLElement("ul") }} + - : Unordered list. + +### 參閱 + +- [行內元素](/zh-TW/docs/Web/HTML/Inline_elements) diff --git a/files/zh-tw/web/html/element/a/index.html b/files/zh-tw/web/html/element/a/index.html deleted file mode 100644 index 9c299eb2b10f79..00000000000000 --- a/files/zh-tw/web/html/element/a/index.html +++ /dev/null @@ -1,283 +0,0 @@ ---- -title: -slug: Web/HTML/Element/a -translation_of: Web/HTML/Element/a ---- -HTML <a>
元素(意為 Anchor)建立了通往其他頁面、檔案、Email 地址、或其他 URL 的超連結。
內容類型 | -流型內容、phrasing content, interactive content, palpable content. | -
---|---|
內容省略 | -Transparent, containing either flow content (excluding interactive content) or phrasing content. | -
標籤省略 | -{{no_tag_omission}} | -
允許的父元素 | -任何允許 phrasing content 或 flow content 的內容,但 <a> 永遠例外(according to the logical principle of symmetry, if <a> tag, as a parent, can not have interactive content, then the same <a> content can not have <a> tag as its parent) | -
Permitted ARIA roles | -{{ARIARole("button")}}, {{ARIARole("checkbox")}}, {{ARIARole("menuitem")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("menuitemradio")}}, {{ARIARole("option")}}, {{ARIARole("radio")}}, {{ARIARole("switch")}}, {{ARIARole("tab")}}, {{ARIARole("treeitem")}} | -
DOM 介面 | -{{domxref("HTMLAnchorElement")}} | -
本元素包含全域屬性。
- -/
and \
are converted to underscores. Most file systems limit some punctuation in file names, and browsers will adjust the suggested name accordingly.
- blob:
URLs and data:
URLs to download content generated by JavaScript, such as pictures created in an image-editor Web app.Content-Disposition:
gives a different filename than this attribute, the HTTP header takes priority over this attribute.Content-Disposition:
is set to inline
, Firefox prioritizes Content-Disposition
, like the filename case, while Chrome prioritizes the download
attribute.#
), which specifies an internal target location (an ID of an HTML element) within the current document. URLs are not restricted to Web (HTTP)-based documents, but can use any protocol supported by the browser. For example, file:
, ftp:
, and mailto:
work in most browsers.Note: You can use href="#top"
or the empty fragment href="#"
to link to the top of the current page. This behavior is specified by HTML5.
PING
will be sent by the browser (in the background). Typically used for tracking.'no-referrer'
means the Referer:
header will not be sent.'no-referrer-when-downgrade'
means no Referer:
header will be sent when navigating to an origin without HTTPS. This is the default behavior.'origin'
means the referrer will be the origin of the page, not including information after the domain.'origin-when-cross-origin'
meaning that navigations to other origins will be limited to the scheme, the host and the port, while navigations on the same origin will include the referrer's path.'unsafe-url'
means the referrer will include the origin and path, but not the fragment, password, or username. This is unsafe because it can leak data from secure URLs to insecure ones.<iframe>
. The following keywords have special meanings:
- _self
: Load the URL into the same browsing context as the current one. This is the default behavior._blank
: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead._parent
: Load the URL into the parent browsing context of the current one. If there is no parent, this behaves the same way as _self
._top
: Load the URL into the top-level browsing context (that is, the "highest" browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this behaves the same way as _self
.Note: When using target
, consider adding rel="noopener noreferrer"
to avoid exploitation of the window.opener
API.
ISO-8859-1
.
- Usage note: This attribute is obsolete in HTML5 and should not be used by authors. To achieve its effect, use the HTTP Content-Type:
header on the linked URL.
shape
attribute, this attribute used a comma-separated list of numbers to define the coordinates of the link on the page.id
and name
could be used simultaneously on a <a>
element as long as they have identical values.
- Usage note: This attribute is obsolete in HTML5, use the global attribute id
instead.
circle
, default
, polygon
, and rect
. The format of the coords attribute depends on the value of shape. For circle
, the value is x,y,r
where x
and y
are the pixel coordinates for the center of the circle and r
is the radius value in pixels. For rect
, the coords attribute should be x,y,w,h
. The x,y
values define the upper-left-hand corner of the rectangle, while w
and h
define the width and height respectively. A value of polygon
for shape requires x1,y1,x2,y2,...
values for coords. Each of the x,y
pairs defines a point in the polygon, with successive points being joined by straight lines and the last point joined to the first. The value default
for shape requires that the entire enclosed area, typically an image, be used.
- usemap
attribute for the {{HTMLElement("img")}} element and the associated {{HTMLElement("map")}} element to define hotspots instead of the shape
attribute.<!-- anchor linking to external file --> -<a href="https://www.mozilla.com/"> -External Link -</a> -- -
<!-- links to element on this page with id="attr-href" --> -<a href="#attr-href"> -Description of Same-Page Links -</a> -- -
Description of Same Page Links
- -This example uses an image to link to the MDN home page. The home page will open in a new browsing context, that is, a new page or a new tab.
- -<a href="https://developer.mozilla.org/en-US/" target="_blank"> - <img src="https://mdn.mozillademos.org/files/6851/mdn_logo.png" - alt="MDN logo" /> -</a> -- -
It's common to create links that open in the user's email program to allow them to send a new message. This is done with a mailto:
link. Here's a simple example:
<a href="mailto:nowhere@mozilla.org">Send email to nowhere</a>- -
For additional details about the mailto
URL scheme, such as including the subject, body, or other predetermined content, see Email links or {{RFC(6068)}}.
Offering phone links is helpful for users viewing web documents and laptops connected to phones.
- -<a href="tel:+491570156">+49 157 0156</a>- -
For additional details about the tel
URL scheme, see {{RFC(3966)}}.
download
attribute to save a <canvas>
as a PNGIf you want to let users download an HTML {{HTMLElement("canvas")}} element as an image, you can create a link with a download
attribute and the canvas data as a file URL:
var link = document.createElement('a'); -link.textContent = 'download image'; - -link.addEventListener('click', function(ev) { - link.href = canvas.toDataURL(); - link.download = "mypainting.png"; -}, false); - -document.body.appendChild(link);- -
You can see this in action at jsfiddle.net/codepo8/V6ufG/2/.
- -HTML 3.2 defines only the name
, href
, rel
, rev
, and title
attributes.
Anchor tags are often abused with the onclick
event to create pseudo-buttons by setting href to "#"
or "javascript:void(0)"
to prevent the page from refreshing. These values cause unexpected behavior when copying/dragging links, opening links in a new tabs/windows, bookmarking, and when JavaScript is still downloading, errors out, or is disabled. This also conveys incorrect semantics to assistive technologies (e.g., screen readers). In these cases, it is recommended to use a {{HTMLElement("button")}} instead. In general you should only use an anchor for navigation using a proper URL.
Whether clicking on an {{HTMLElement("a")}} causes it to become focused varies by browser and OS.
- -Desktop Browsers | -Windows 8.1 | -OS X 10.9 | -
---|---|---|
Firefox 30.0 | -Yes | -Yes | -
Chrome ≥39 - (Chromium bug 388666) |
- Yes | -Yes | -
Safari 7.0.5 | -N/A | -Only when it has a tabindex |
-
Internet Explorer 11 | -Yes | -N/A | -
Presto (Opera 12) | -Yes | -Yes | -
Mobile Browsers | -iOS 7.1.2 | -Android 4.4.4 | -
---|---|---|
Safari Mobile | -Only when it has a tabindex |
- N/A | -
Chrome 35 | -??? | -Only when it has a tabindex |
-
{{Compat("html.elements.a")}}
- -