div 和 svg 的问题 ,怎么用JavaScript得到svg中的函数呢?
我在一个页面中有两个div,每个div里embed了两个svg文件,我想在svg2文件中调用svg1中的JavaScript函数gg(),
我该怎么办呢?
<div id="svgDiv" >
<embed width="1006" height="616" type="image/svg-xml" id="svg" pluginspage="http://www.adobe.com/svg/viewer/install/" src="svg1.svg" >
</DIV>
<div id="toolbar" >
<embed width="800" height="30" type="image/svg-xml" id="svgBar" pluginspage="http://www.adobe.com/svg/viewer/install/" src="svg2.svg" >
</div>
svg2中javaScript中得到可以用parent.svgDiv.document.getElementById("svg");得到embed!
[解决办法]
没有接触过这个,这样试试。。。
parent.svgDiv.document.getElementById("svg").gg()
[解决办法]
突然要用svg
找了个例子,楼主可以看看。。。
文件rec.svg
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="400" height="400" viewBox="0 0 400 400" onload="init(evt)">
<script language="javascript">
<![CDATA[
var SVGDocument=null;
function init(evt)
{
SVGDocument=evt.getTarget().getOwnerDocument();
}
function changeColor(color)
{
SVGDocument.getElementById("rect").getStyle().setProperty("fill",color);
}
// ]]>
</script>
<rect id="rect" x="100" y="100" width="200" height="200" style="fill:red"/>
</svg>
文件rectCon.html
html文件:
<html>
<body>
<embed name="svg" type="image/svg+xml" src="rec.svg" width="400" height="400">
<br>
<input type="button" value="green" onClick="svg.window.changeColor(this.value)">
</body>
</html>
[解决办法]
SVG没有怎么看过 ,加一句parent.svgDiv.document.getElementById("svg").prototype=new gg();看看行不