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

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

創(chuàng)建擴(kuò)展 SVGCircleElement 的自定義元素時(shí)出錯(cuò)

創(chuàng)建擴(kuò)展 SVGCircleElement 的自定義元素時(shí)出錯(cuò)

皈依舞 2022-09-02 21:02:33
我有以下Node類,我用它來創(chuàng)建自定義元素。node-elementclass Node extends SVGCircleElement{    static get observedAttributes() {        return ["coordinates"];      }    constructor()    {        super();        this.attributeMap = {coordinates:(coordinates)=>this.updateCoordinates(coordinates)}    }    connectedCallback(){        this.initNode();    }    updateCoordinates(coordinates)    {        this.setAttribute("cx",`${coordinates.x}`);        this.setAttribute("cy",`${coordinates.y}`);        this.setAttribute("r",50);    }    initNode()    {        this.className="node";    }    attributeChangedCallback(name,oldValue,newValue)    {        if(oldValue!==newValue)        {            this.attributeMap[name](JSON.parse(newValue))        }    }}我注冊(cè)此元素使用:-customElements.define('node-element',Node);我正在創(chuàng)建此元素,如下所示:-let newNode = document.createElement("node-element");這就是我得到以下錯(cuò)誤的地方:-Uncaught TypeError: Illegal constructor    at new Node (index.js:9)    at SVGSVGElement.drawNode (index.js:43)第 43 行對(duì)應(yīng)于 createElement 代碼。
查看完整描述

1 回答

?
慕勒3428872

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

很想被證明是錯(cuò)誤的,只是在SVG項(xiàng)目上花了2個(gè)月

AFAIK,你不能擴(kuò)展SVG元素

只能在 HTML 命名空間中創(chuàng)建自定義元素http://www.w3.org/1999/xhtml

SVG 元素位于 SVG 命名空間中http://www.w3.org/2000/svg

從文檔: https://html.spec.whatwg.org/multipage/custom-elements.html#element-definition

如果擴(kuò)展的元素接口和 HTML 命名空間是 HTMLUnknownElement,
則拋出一個(gè)“NotSupportedError”DOMException。

如果命名空間不是 HTML 命名空間,則返回 null

正在進(jìn)行的關(guān)于允許其他命名空間的 W3C 討論如下:https://github.com/w3c/webcomponents/issues/634


HTML 命名空間也有限制

Apple/Safari實(shí)現(xiàn)了Autonomous Custom Elements(從HTMLElement擴(kuò)展而來)

但拒絕實(shí)現(xiàn)自定義內(nèi)置元素(從 HTML 命名空間擴(kuò)展任何內(nèi)置元素)


如果要生成 SVG,則必須擴(kuò)展并生成整個(gè) SVG 標(biāo)記:HTMLElement

<svg xmlns='http://www.w3.org/2000/svg' viewBox='V'><circle cx='X' cy='Y' r='R'/></svg>
查看完整回答
反對(duì) 回復(fù) 2022-09-02
  • 1 回答
  • 0 關(guān)注
  • 97 瀏覽
慕課專欄
更多

添加回答

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