在 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>
泛舟湖上清波郎朗
相关分类