--- title: is slug: Web/HTML/Global_attributes/is tags: - Global attributes - HTML - Reference - is translation_of: Web/HTML/Global_attributes/is ---
{{HTMLSidebar("Global_attributes")}}

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
{{SpecName('HTML WHATWG', "custom-elements.html#attr-is", "is")}} {{Spec2('HTML WHATWG')}}  

浏览器兼容

{{Compat("html.global_attributes.is")}}

参见