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

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

創(chuàng)建自定義 html 元素時(shí)未調(diào)用連接的回調(diào)

創(chuàng)建自定義 html 元素時(shí)未調(diào)用連接的回調(diào)

哈士奇WWW 2021-11-18 09:55:35
我試圖使用 JavaScript 在 HTML 中創(chuàng)建自定義標(biāo)記。我想使用 ES6 JavaScript 語(yǔ)法創(chuàng)建自定義元素。我編寫了此代碼來(lái)創(chuàng)建自定義元素:customElements.define('neo-element', NeoElement);function NeoElement (){    var ref =  Reflect.construct(HTMLElement,[], this.constructor) ;    return ref;};NeoElement.prototype = Object.create(HTMLElement.prototype);NeoElement.prototype.constructor = NeoElement;NeoElement.prototype.connectedCallback = function(){    this.innerHTML = `<h1>Hello world</h1>`;};<neo-element></neo-element>我已經(jīng)驗(yàn)證 NeoElement 正確擴(kuò)展了 HTMLElement,但仍然沒(méi)有在<neo-element>標(biāo)簽內(nèi)打印任何內(nèi)容。任何人都可以查看代碼并告訴我 ES5 語(yǔ)法中缺少什么嗎?
查看完整描述

1 回答

?
慕沐林林

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

它不工作,因?yàn)槟愦螂娫抍ustomElements.define-and從而升級(jí)<neo-element>到的實(shí)例NeoElement,之前你已經(jīng)定義NeoElement.prototype,NeoElement.prototype.constructor和NeoElement.prototype.connectedCallback。


如果你移動(dòng)customElements.define到最后它工作正常:


function NeoElement() {

    var ref = Reflect.construct(HTMLElement,[], this.constructor) ;

    return ref;

};

NeoElement.prototype = Object.create(HTMLElement.prototype);

NeoElement.prototype.constructor = NeoElement;

NeoElement.prototype.connectedCallback = function(){

    this.innerHTML = `<h1>Hello world</h1>`;

};

customElements.define('neo-element', NeoElement);

<neo-element></neo-element>


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

添加回答

舉報(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)