结合SVG,HTML和Javascript [英] Combining SVG, HTML and Javascript
本文介绍了结合SVG,HTML和Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的HTML文件:
I have an HTML file that looks somehow like this:
<html>
<div id="test"> ... </div>
<object data="pic.svg" [...]></object>
</html>
在pic.svg中,我有一个元素,比方说一个圆,我想要实现像这样:
Inside pic.svg, I have an element, let's say, a circle, and I want to realize something like that:
<circle onClick="doSomething()" [...]>
现在,在js函数doSomething()中(即当某人点击圆圈时),我想改变我的测试-div。如何做到这一点?
Now, in the js function doSomething() (i.e. when someone clicks on the circle) I want to change my "test"-div. How to do this?
推荐答案
您可以像这样从svg中访问父文档(以及其中的元素):
You can access the parent document (and consequently the elements there) from inside the svg like this:
var divInParentDocument = window.parent.document.getElementById('test');
下面是一个(稍微复杂一点的)示例,其中显示了如何在svg中的父级html文档中调用函数。
Here's a (slightly more complex) example showing how to call a function in the parent html document from inside an svg.
这篇关于结合SVG,HTML和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文