在javascript中的对象标记上的svg文件内调用函数
在我的HTML页面中,我得到:在javascript中的对象标记上的svg文件内调用函数,javascript,svg,Javascript,Svg,在我的HTML页面中,我得到: <script language="JavaScript"> function mostrar(blo) { var str = ""; ... window.document.tbl27svg.pinta(str); } 因此,我尝试了几种方法在tbl27.svg文件上调用pinta()函数。但我总是遇到一个java脚本错误: “对象不支持此属性或方法”请确保将pinta()函数声明放在window.document.tbl2
<script language="JavaScript">
function mostrar(blo) {
var str = "";
...
window.document.tbl27svg.pinta(str);
}
因此,我尝试了几种方法在tbl27.svg文件上调用pinta()函数。但我总是遇到一个java脚本错误:
“对象不支持此属性或方法”请确保将
pinta()
函数声明放在window.document.tbl27svg.pinta(str)之前代码>:
函数pinta(){
...
}
功能mostrar(blo){
var str=“”;
...
window.document.tbl27svg.pinta(str);
}
pinta()
位于以下文件中:tbl27.svg和window.document.tbl27svg.pinta(str)
位于html页面中,该页面将此文件包含在标记
中,检查var a=document.getElementById('tbl27svg').getSVGDocument()是否正确代码>返回一个值。@您使用的浏览器是什么?它也返回未定义的值。但我最终还是用了一些类似的东西,比如在这个页面中所做的:。这似乎奏效了。非常感谢。
<object id="tbl27svg" data="../../imagenes/svg/tbl27.svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1100px" height="1000px" type="image/svg+xml"/>
parent.pinta=pinta
function inicia(event){
SVGDocument = event.target.ownerDocument;
}
function pinta(strSVG){
var nuevoNodo=parseXML(strSVG, document);
if(document.getElementById('grafico1').childNodes.length>0){
if(!document.getElementById('grafico2').childNodes.length>0)
SVGDocument.getElementById("grafico2").appendChild(nuevoNodo);
}else{
SVGDocument.getElementById("grafico1").appendChild(nuevoNodo);
}
}
<script>
function pinta(){
...
}
function mostrar(blo) {
var str = "";
...
window.document.tbl27svg.pinta(str);
}
</script>