aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/customelementregistry/get/index.html
blob: 5b6cb1b5643536f433e8328d3f899a3f798d4f59 (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
68
69
70
71
72
---
title: CustomElementRegistry.get()
slug: Web/API/CustomElementRegistry/get
tags:
  - CustomElementRegistry
  - Experimental
  - Web Components
  - custom elements
translation_of: Web/API/CustomElementRegistry/get
---
<p>{{APIRef("CustomElementRegistry")}}</p>

<p><span class="seoSummary"> {{domxref("CustomElementRegistry")}}<code><strong>get()</strong></code>方法返回以前定义自定义元素的构造函数.</span></p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>constructor</em> = customElements.get(<em>name</em>);
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt>name</dt>
 <dd>你想要返回引用的构造函数的自定义元素的名字。</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>指定名字的自定义元素的构造函数,如果没有使用该名称的自定义元素定义,则为<code>undefined</code></p>

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

<pre class="brush: js">customElements.define('my-paragraph',
  class extends HTMLElement {
    constructor() {
      super();
      let template = document.getElementById('my-paragraph');
      let templateContent = template.content;

      const shadowRoot = this.attachShadow({mode: 'open'})
        .appendChild(templateContent.cloneNode(true));
  }
})

// Return a reference to the my-paragraph constructor
<span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">let ctor = customElements.get('my-paragraph');</span></span></span>
</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#dom-customelementregistry-get", "customElements.get()")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

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

<div>


<p>{{Compat("api.CustomElementRegistry.get")}}</p>
</div>