is

is 全局属性 允许你指定标准 HTML 元素的行为应类似于已定义的自定义内置元素(有关更多详细信息,请参阅 使用自定义元素)。

¥The is global attribute allows you to specify that a standard HTML element should behave like a defined custom built-in element (see Using custom elements for more details).

仅当指定的自定义元素名称已在当前文档中成功 defined 并扩展其所应用的元素类型时,才能使用此属性。

¥This attribute can only be used if the specified custom element name has been successfully defined in the current document, and extends the element type it is being applied to.

示例

¥Examples

以下代码取自我们的 word-count-web-component 示例 (也看到它直播)。

¥The following code is taken from our word-count-web-component example (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 omitted for brevity
    // …
  }
}

// Define the new element
customElements.define("word-count", WordCount, { extends: "p" });
html
<p is="word-count"></p>

规范

Specification
HTML Standard
# attr-is

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also