aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/html/global_attributes/is/index.html
blob: 27e3e21cea8c008b9adbe8f1241b95e34e73fff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: is
slug: Web/HTML/Global_attributes/is
tags:
  - Global attributes
  - HTML
  - Reference
  - is
translation_of: Web/HTML/Global_attributes/is
---
<div>{{HTMLSidebar("Global_attributes")}}</div>

<p><span class="seoSummary">is 全局属性 ( <a href="/en-US/docs/Web/HTML/Global_attributes">global attribute</a> ) 允许您指定标准 HTML 元素像定义的内置元素一样工作(请参阅使用自定义元素 ( <a href="/en-US/docs/Web/Web_Components/Using_custom_elements">Using custom elements</a> ) 以获取更多详细信息)。</span></p>

<p>只有在当前文档中已成功定义 ( <a href="/en-US/docs/Web/API/CustomElementRegistry/define">defined</a> ) 指定的自定义元素名称并且扩展了要应用的元素类型时,才能使用此属性。</p>

<h2 id="示例">示例</h2>

<p> 以下代码来自我们的 <a href="https://github.com/mdn/web-components-examples/tree/master/word-count-web-component">word-count-web-component</a> 示例(<a href="https://mdn.github.io/web-components-examples/word-count-web-component/">see it live also</a>)。</p>

<pre class="brush: js">// Create a class for the element
class WordCount extends HTMLParagraphElement {
  constructor() {
    // Always call super first in constructor
    super();

    // Constructor contents ommitted for brevity
    ...

  }
}

// Define the new element
customElements.define('word-count', WordCount, { extends: 'p' });</pre>

<pre class="brush: html">&lt;<span class="pl-ent">p</span> <span class="pl-e">is</span>=<span class="pl-s"><span class="pl-pds">"</span>word-count<span class="pl-pds">"</span></span>&gt;&lt;/<span class="pl-ent">p</span>&gt;</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "custom-elements.html#attr-is", "is")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>



<p>{{Compat("html.global_attributes.is")}}</p>

<h2 id="参见">参见</h2>

<ul>
 <li>All <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</li>
</ul>

<p> </p>