如何将 JavaScript 链接到 SVG?
我有一个使用 SVG 和 JS 的项目。现在SVG负责调用JS。在 SVG 代码中间有一条类似这样的指令:
planta30263.svg
<?xml version="1.0" encoding="UTF-8"?>
....
<script type="text/javascript" xlink:href="tatu1/svgEditarVisualizacao.js" xlink:actuate="onLoad" xlink:show="other" xlink:type="simple" />
.....
但是有时需要将目录从一台服务器更改到另一台服务器。 (tatu1 -> tatu2) 所以,我想知道是否有办法让JS在嵌入SVG的页面中调用SVG,即外部调用。
vis_rota.jsp
....
<embed src="<%=planta%>" id="plantaSVG" type="image/svg+xml" name="plantaSVG" />
....
I have a project that works with SVG and JS. Nowadays the SVG is responsible for calling the JS. In the middle of the SVG code there is an instruction like that:
planta30263.svg
<?xml version="1.0" encoding="UTF-8"?>
....
<script type="text/javascript" xlink:href="tatu1/svgEditarVisualizacao.js" xlink:actuate="onLoad" xlink:show="other" xlink:type="simple" />
.....
However sometimes it's necessary to change the directory from one server to another. (tatu1 -> tatu2) So, I'd like to know if there is a way to make JS calls the SVG in the page which SVG is embedded, an external calling.
vis_rota.jsp
....
<embed src="<%=planta%>" id="plantaSVG" type="image/svg+xml" name="plantaSVG" />
....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
脚本元素上的 xlink:actuate、xlink:show 和 xlink:type 属性不是必需的,您可以安全地删除它们。
最好使用
如果您想从 svg 调用函数到引用它的文档,请参阅 svg 和 html 之间的脚本 一些示例。
The xlink:actuate, xlink:show and xlink:type attributes on the script element are not necessary, you can safely remove them.
It's better to use
<object>
rather than<embed>
because then you can then provide fallback content if a browser lacks the ability to display svg, or if it has been disabled for any reason. For more information see the SVG Primer.If you want to call functions from the svg to the document that referenced it, then see scripting between svg and html for some examples.
不确定你想要什么和插头,但是
在 iscriptdesign 您可以看到一些 JavaScript 操作来查看不同的 svg 图像。在线调整图像,并使用 html 5 的文件 api 上传它们。
Not sure what you want and a plug but
at iscriptdesign you can see some javascript manupulation to view different svg images. Adapt images online, and upload them using html 5's file api.