以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  关于IE,Firefox下的SVG文件Dom对象的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=32562)


--  作者:mikezhuyan
--  发布时间:5/17/2006 3:27:00 PM

--  关于IE,Firefox下的SVG文件Dom对象的问题
本人是SVG初学者,在IE和Firefox下对SVG编了几个小程序。
发现在如果用IE打开SVG文件(安装了Adobe的插件),使用javascript对SVG文件进行操作,例如:document.getElementId("");可以返回SVGElement对象,但是如果在Firefox下用document.getElementId("");对同样的SVG文件进行操作,则返回的结果为空?为什么?在firefox下怎样使用getElementId方法?小弟使用了SVGDocument对象依然是同样的结果,哪位高人指点一下,谢谢。代码如下 :
SVG文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1200" height="640">
<defs>
<title>test</title>
</defs>
  <script xlink:href="testff.js"/> 
<rect id="test" x="0" y="0" width="1000" height="1000" fill="black" /> 
</svg>

testff.js文件:
// JavaScript Document
var test=new Object();

test.test=function()
{
 document.documentElement.addEventListener("mousedown",mouse,false);
 //alert(document.getElementById("test"));
}
function mouse()
{
 alert(document.getElementById("test"));
}
test.test();


--  作者:mikezhuyan
--  发布时间:5/17/2006 3:37:00 PM

--  
testff.js的代码贴错了,如果对SVG文件设置了鼠标监听事件,则在firefox下就可以得到element,而如果是

test.test=function()
{
alert(document.getElementById("test"));
}
test.test();

则在firefox下就不可以用了,为什么?IE下,可以正常工作。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
95.703ms