我要做的是在svg中更换图片,添加了JS在svg中。
在浏览器上能够很好的运行,但是在蜡染的JSVGCanvas中却没有反应。
有没有办法解决这个问题呢?
先谢谢了!
在SVG中添加了Javascript,但是不能在JSVGCanvas中运行。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- Dead_Knight 2013-04-26 14:00关注
帮你解决了这个问题,因为在浏览器中使用javascript操作svg的元素没有那么规范,而batik操作svg元素需要严格按照w3c的svg规范,所以svg文件中的方法需要改为:
[code="java"]
function dragOn(spath){
var imgView = document.getElementById("imgView");
imgView.setAttributeNS( "http://www.w3.org/1999/xlink", "href", spath );
}
[/code]
我已经测试过,具体可参考:
[url]http://www.w3.org/Graphics/SVG/WG/wiki/Href[/url]
下面这些方式中,就最后两个是Correct正确的。
[code="java"]
el.setAttribute( "href", "foo.png" );
el.setAttribute( "xlink:href", "foo.png" );
el.setAttributeNS( "xlink:href", "foo.png" );
el.setAttributeNS( "xlink", "href", "foo.png" );
el.setAttributeNS( xlink, "href", "foo.png" ); (where there is no JS variable called "xlink")
el.setAttributeNS( "http://www.w3.org/1999/xlink", "href", "foo.png" ); (Correct)
var xlinkns = "http://www.w3.org/1999/xlink"; el.setAttributeNS( xlinkns, "href", "foo.png" ); (Correct)[/code]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报