html的windows属性,HTML DOM window customElements属性用法及代码示例

customElements属性返回对CustomElementRegistry对象的引用,该对象可进一步用于注册新的自定义元素,从而获取有关先前已注册的自定义元素的信息。

用法:

var obj = window.customElements;

返回值:

CustomElementRegistry Object:此属性返回一个对象,其中包含有关定义的自定义元素的详细信息。

例:在此示例中,我们将获取有关自定义元素的信息,并将使用define()方法创建一个自定义元素。

customElements property

GeeksForGeeks

HTML | customElements property

click here

var arr = document.getElementById("arr");

function Geeks() {

let customElementRegistry = window.customElements;

class CustomTitle extends HTMLElement {

constructor() {

super()

this.attachShadow({ mode:'open' })

this.shadowRoot.innerHTML = `

Newly Defined Custom Element's Data

`

}

}

window.customElements.define(

'custom-title', CustomTitle);

console.log(customElementRegistry)

}

输出:

按钮单击之前:

ecbd930917245663bdfcaefd706c485c.png

单击按钮后:

1ec5fc4bec5c6860087c004555468ae1.png

customElements对象:

4a8ba9dadc60a148cfb1689b927484b0.png

支持的浏览器:

谷歌浏览器

Edge

Firefox

Safari

Opera

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值