SVG对象引用的小例子(开关的)
在获取getChildNodes元素时,不支持firefox,网上查了一下,好像是firefox并不是完全支持SVG。
在获取getChildNodes元素时,不支持firefox,网上查了一下,好像是firefox并不是完全支持SVG。
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
width="100%" height="100%" >
<script type="text/javascript">
<![CDATA[
function setDisplayAttribute(obj){
if(obj.getAttribute('display') == 'none')
obj.setAttribute('display','');
else
obj.setAttribute('display','none');
}
function lineGClick(evt){
var svgDoc = evt.target.ownerDocument;
var lineObjs = svgDoc.getElementById('lineG1').getChildNodes();
var lineObj = null;
var max = lineObjs.length;
for(var i=1;i<(max-1);i+=2){
lineObj = lineObjs.item(i);
if(lineObj.id=='lineA' || lineObj.id=='lineB'){
setDisplayAttribute(lineObj);
}
}
}
]]>
</script>
<defs>
<g id='lineG1' >
<line id='line1' fill="none" stroke="#000000" stroke-width="2" x1="1" y1="0" x2="1" y2="56.693"/>
<line id='lineA' fill="none" display="none" stroke="#000000" stroke-width="2" x1="1" y1="54" x2="1" y2="110.693"/>
<line id='line2' fill="none" stroke="#000000" stroke-width="2" x1="1" y1="108" x2="1" y2="164.693"/>
<line id='lineB' fill="none" stroke="#000000" stroke-width="2" x1="1" y1="54" x2="42.322" y2="92.815"/>
</g>
</defs>
<use x='100' y='100' xlink:href="#lineG1" onclick="lineGClick(evt)"/>
<use x='200' y='100' xlink:href="#lineG1" onclick="lineGClick(evt)"/>
</svg>