复制代码代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head /head body svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300" script type="text/ecmascript" ![CDATA[ function showRectColor() { alert(document.getElementById("myBlueRect").getAttributeNS(null,"fill")); } function showRectArea(evt) { var width = parseFloat(evt.target.getAttributeNS(null,"width")); var height = parseFloat(evt.target.getAttributeNS(null,"height")); alert("The rectangle area is: " + (width * height)); } function showRootChildrenNr() { alert("Nr of Children: "+document.documentElement.childNodes.length); } ]] /script g id="firstGroup" rect id="myBlueRect" width="100" height="50" x="40" y="20" fill="blue" / text x="40" y="100" Click on this text to show rectangle color. /text text x="40" y="130" Click on rectangle to show rectangle area. /text text x="40" y="160" Click on this text to show the number of child tspan x="40" dy="20" elements of the root element. /tspan /text /g /svg /body /html