以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  为什么通过DOM增加的symbol中的cir2不会显示?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=35941)


--  作者:upc2neiep
--  发布时间:7/23/2006 8:32:00 PM

--  为什么通过DOM增加的symbol中的cir2不会显示?
<?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 xmlns="http://www.w3.org/2000/svg" onload="init(evt)">
<title>SVG drawing</title>
<script language="jajvasvript">
//变量声明
var svgDoc,svgRoot,drawing,newshape;
var svgns="http://www.w3.org/2000/svg";

//svg初始化
function init(evt)
{
    svgDoc=evt.target.ownerDocument;
    svgRoot=svgDoc.rootElement;

    //绘图区标识
    drawing=svgDoc.getElementById("drawing");
}

function add()
{
 newshape=svgDoc.createElementNS(svgns,"use");
 newshape.setAttribute("x",100);
 newshape.setAttribute("y",100);
 newshape.setAttribute("width",50);
 newshape.setAttribute("height",50);
 newshape.setAttribute("xlink:href","#G");
 drawing.appendChild(newshape);
 alert(newshape);
}
</script>
<desc>by llh 2006-05-10</desc>
<use x="300" y="300" width="100" height="100" xlink:href="#cir2"/>
<g id="layer#1">
<rect x="100" y="100" width="100" height="100" fill="#ff0000" onmousedown="add()"/>
</g>
<g id="user">
 <defs>
 <symbol id="cir2" viewBox="0 0 100 100">
     <g stroke="red" fill="none" stroke-width="1">
  <circle cx="20" cy="20" r="20"/>
  <circle cx="60" cy="60" r="20"/>
     </g>
 </symbol>
 </defs>
</g>
<g id="drawing"></g>
</svg>

这里面svg文件本身的use能够正常显示,而通过DOM增加的USE却不能够?
我想是不是<use>只有在同SVG文件一起加载的时候才有效

如果要动态添加几个图形的组合,该怎么解决呢?


--  作者:upc2neiep
--  发布时间:7/24/2006 9:33:00 PM

--  
http://bbs.xml.org.cn/dispbbs.asp?boardID=21&ID=33791
正确答案 100分
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms