is

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

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

示例

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

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

规范

Specification
HTML Standard
# attr-is

浏览器兼容性

BCD tables only load in the browser

参见