此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

is

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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
# attr-is

浏览器兼容性

参见