我能够使用 ECMAScript 操作 SVG 链接元素的 xlink:href 属性,如下所示:
var xlinkns = "http://www.w3.org/1999/xlink";
myLink.setAttributeNS(xlinkns, "xlink:href", "#");//add href attribute to the link
myLink.removeAttributeNS(xlinkns, "href");//remove the href attribute from the link
我的问题是:使用 javascript 或 snap SVG 执行完全相同的操作的正确语法是什么?
最佳答案
瞬间就是
element.attr("xlink:href", "http://google.com");
Snap 将为您计算出命名空间
在 Ecmacript(这是 javascript 的同义词)中,它
var xlinkns = "http://www.w3.org/1999/xlink";
var myLink = document.getElementById("link");
myLink.setAttributeNS(xlinkns, "href", "http://google.com");
alert(myLink.getAttributeNS(xlinkns, "href"));
<svg><a id="link" xlink:href="http://stackoverflow.com"/></svg>
关于javascript - snap svg 添加/删除链接属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049953/