在 Chrome 和 FF 中,如果我運行這一行SOME_SVG_NODE.setAttributeNS("http://example.com","ex:attr",1)然后這一行稍后:SOME_SVG_NODE.setAttributeNS("http://example.com","ex:attr",2)結果是: <node ex:attr="2">...在 Safari 中,結果是: <node ex:attr="1" attr"2">...在 Safari 中,如果我接連運行這兩行,結果匹配 Chrome 和 FF ...我是否遺漏了什么或做了一些不規則的事情?是否有某種原因對 setAttributeNS 的連續調用是不明確的,以至于不同的瀏覽器對它的解釋不同?完整示例<!DOCTYPE html><html><head> <title></title></head><body> <svg xmlns="http://www.w3.org/2000/svg"> <g></g> </svg> <script type="text/javascript"> let g = document.querySelector("g") g.setAttributeNS("http://example.com","ex:attr","1") g.setAttributeNS("http://example.com","ex:attr","2") console.log(g) document.addEventListener("mousedown",e=>{ g.setAttributeNS("http://example.com","ex:attr","3") console.log(g) }) </script></body></html>
在 Safari 中,重復 setAttributeNS() 調用會創建附加屬性
慕田峪7331174
2021-08-26 14:31:21