第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

未注冊(cè)的 HTML 自定義元素和注冊(cè)的 HTML 自定義元素有什么區(qū)別?

未注冊(cè)的 HTML 自定義元素和注冊(cè)的 HTML 自定義元素有什么區(qū)別?

qq_遁去的一_1 2023-08-24 10:05:06
如果我無(wú)法注冊(cè)自定義元素,我注意到我仍然可以:使用CSS設(shè)置未注冊(cè)元素的樣式使用JS將事件添加到未注冊(cè)的元素等例子:// REGISTER <my-custom-element-1>class MyRegisteredCustomElement1 extends HTMLElement {  constructor() {    super();  }};customElements.define('my-custom-element-1', MyRegisteredCustomElement1);// ATTACH EVENT LISTENERS TO BOTH CUSTOM ELEMENTSconst myCustomElement1 = document.getElementsByTagName('my-custom-element-1')[0];const myCustomElement2 = document.getElementsByTagName('my-custom-element-2')[0];const customElementAlert = (e) => {  switch (e.target.nodeName.toLowerCase()) {      case ('my-custom-element-1') : console.log('I\'m a registered custom element and I can be scripted and styled.'); break;    case ('my-custom-element-2') : console.log('I\'m an unregistered custom element. Nevertheless, I can be scripted and styled TOO.'); break;  }}myCustomElement1.addEventListener('click', customElementAlert, false);myCustomElement2.addEventListener('click', customElementAlert, false);:not(:defined) {  border: 1px dashed rgb(0, 0, 0);}my-custom-element-1,my-custom-element-2 {  float: left;  display: inline-block;  width: 100px;  height: 100px;  margin-right: 12px;  padding: 6px;  text-align: center;  font-weight: bold;  cursor: pointer;}my-custom-element-1 {  color: rgb(255, 255, 255);  background-color: rgb(255, 0, 0);}my-custom-element-1::after {  content: 'I\'m a registered custom element.\A CLICK ME';}my-custom-element-2 {  background-color: rgb(255, 255, 0);}my-custom-element-2::after {  content: 'I\'m an unregistered custom element.\A CLICK ME';}<my-custom-element-1></my-custom-element-1><my-custom-element-2></my-custom-element-2>如果未注冊(cè)的自定義元素可以設(shè)置樣式和腳本,那么注冊(cè)自定義元素具體可以實(shí)現(xiàn)什么功能?
查看完整描述

1 回答

?
MYYA

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊

基本上,它將元素與您為其設(shè)置的類相關(guān)聯(lián)。它:

  • 允許使用生命周期回調(diào),例如connectedCallback(和disconnectedCallback)

  • 允許在構(gòu)造函數(shù)中自定義邏輯和屬性。

您創(chuàng)建的元素my-custom-element-2只是一個(gè)常規(guī) HTML 元素,沒(méi)有您為其指定的特定類。my-custom-element-2如果你檢查 DOM,你會(huì)看到is的類,而isHTMLElement的類。my-custom-element-1myRegisteredCustomElement1


查看完整回答
反對(duì) 回復(fù) 2023-08-24
  • 1 回答
  • 0 關(guān)注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)