翻译正在进行中。

is 全局属性( global attribute )允许您指定标准HTML元素像定义的内置元素一样工作(请参阅使用自定义元素( Using custom elements )以获取更多详细信息)。

只有在当前文档中已成功定义( defined )指定的自定义元素名称并且扩展了要应用的元素类型时,才能使用此属性。

示例

 以下代码来自我们的 word-count-web-component 示例(see it live also)。

// 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' });
<p is="word-count"></p>

规范

Specification Status Comment
HTML Living Standard
is
Living Standard  

浏览器兼容

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support66 No

591

Yes — 592

No53 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support6666 No

591

Yes — 592

53 No No

1. From version 59: this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

2. Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

参见

 

文档标签和贡献者

 此页面的贡献者: Kollar93
 最后编辑者: Kollar93,