snap svg add/remove link 属性

snap svg add/remove link attribute

我可以像这样使用 ECMAScript 操作 SVG link 元素的 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://whosebug.com"/></svg>