以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  如何得到<g>下的元素呢?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=31154)


--  作者:jeeq
--  发布时间:4/24/2006 11:42:00 AM

--  如何得到<g>下的元素呢?
<g id="test1" >
<rect x="60" y="162.703" fill="#FFFFFF" stroke="#5DF40C" stroke-width="2" width="12" height="12"  xx ="73" yy="175" />
</g>

在js里面根据
var o = document.getElementById("e1").getSVGDocument().getElementById(id);
得到了<g>这个元素,现在我要通过<g>得到它下面的子结点<rect>我该怎么写呢?


--  作者:upc2neiep
--  发布时间:5/6/2006 12:57:00 PM

--  
<g id="shape" onclick="setShape(evt)">
  <line id="LineS" x1="40" y1="100" x2="70" y2="100" style="stroke:red;stroke-width:1"/>
  <rect id="RectS" x="40" y="110" width="30" height="10" style="fill:white;stroke-width:1;stroke:red"/>
  <circle id="CircleS" cx="60" cy="135" r="10" style="fill:white;stroke-width:1;stroke:red"/>
</g>


function setShape(mousedown_event)
   {
    shapeTag=mousedown_event.target.tagName
    shapeObj=shape.childNodes;
    
    for(i=0;i<shapeObj.length;i++)
    {
     if(shapeObj.item(i).tagName==shapeTag)
     {
      shapeObj.item(i).style.setProperty("stroke-width","3","");
     }
     else
     {
      shapeObj.item(i).style.setProperty("stroke-width","1","");
     }
    }     
   }


--  作者:upc2neiep
--  发布时间:5/6/2006 12:58:00 PM

--  
大概是这样吧 我也是刚学
看见类似 贴过来
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
4,277.344ms