aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/html/global_attributes/id
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/html/global_attributes/id
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/html/global_attributes/id')
-rw-r--r--files/zh-cn/web/html/global_attributes/id/index.html63
1 files changed, 63 insertions, 0 deletions
diff --git a/files/zh-cn/web/html/global_attributes/id/index.html b/files/zh-cn/web/html/global_attributes/id/index.html
new file mode 100644
index 0000000000..d1ccbcd3ec
--- /dev/null
+++ b/files/zh-cn/web/html/global_attributes/id/index.html
@@ -0,0 +1,63 @@
+---
+title: id
+slug: Web/HTML/Global_attributes/id
+translation_of: Web/HTML/Global_attributes/id
+---
+<div>{{HTMLSidebar("Global_attributes")}}</div>
+
+<p><span class="seoSummary"><strong><code>id</code> <a href="/zh-CN/docs/Web/HTML/Global_attributes">全局属性</a></strong>定义了一个全文档唯一的标识符 (ID)。它用于在链接(使用<a href="/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Identifying_resources_on_the_Web#片段">片段</a>)、脚本和样式(通过 {{glossary("CSS")}})中辨识元素。</span></p>
+
+<div>{{EmbedInteractiveExample("pages/tabbed/attribute-id.html","tabbed-shorter")}}</div>
+
+<div class="blockIndicator warning">
+<p>该属性的值是一个不透明(opaque)字符串,这意味着网页开发者不能使用它来传递人类可读的信息。</p>
+</div>
+
+<p><code>id</code> 的值不得包含空白字符({{glossary("whitespace")}},包括空格和制表符等)。浏览器会将不符合规范的 ID 中的空白字符视为 ID 的一部分。与允许以空格分隔值的 {{htmlattrxref("class")}} 属性不同,元素只能拥有一个 ID 值。</p>
+
+<div class="note">
+<p><strong>注意:</strong>使用除 {{glossary("ASCII")}} 字母、数字、<code>_</code>、<code>-</code> 和 <code>.</code> 以外的字符可能会造成兼容性问题,因为 HTML 4 中不允许使用它们。虽然这个限制在 {{glossary("HTML5")}} 中被解除了,但为兼容性考虑 ID 应该以字母开头。</p>
+</div>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', "dom.html#the-id-attribute", "id")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>No change from latest snapshot, {{SpecName('HTML5.1')}}</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5.1', "dom.html#the-id-attribute", "id")}}</td>
+ <td>{{Spec2('HTML5.1')}}</td>
+ <td>Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "dom.html#the-id-attribute", "id")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>Snapshot of {{SpecName('HTML WHATWG')}}, now accept <code>'_'</code>, <code>'-'</code> and <code>'.'</code> if not at the beginning fo the id. It is also a true global attribute.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML4.01', 'struct/global.html#adef-id', 'id')}}</td>
+ <td>{{Spec2('HTML4.01')}}</td>
+ <td>Supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("html.global_attributes.id")}}</p>
+
+<h2 id="另请参阅">另请参阅</h2>
+
+<ul>
+ <li>所有的<a href="/zh-CN/docs/Web/HTML/Global_attributes">全局属性</a>。</li>
+ <li>反映该属性的 {{domxref("Element.id")}}。</li>
+</ul>