每天一個JavaScript執行個體-從js指令碼中訪問object元素中的SVG,objectsvg
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>每天一個JavaScript執行個體-從js指令碼中訪問object元素中的SVG</title><style></style></head><body><object id="object" data = "每天一個JavaScript執行個體-SVG中的javaScript展示.svg" style="padding:20px;width:600px;height:600px;"><p>No SVG support</p></object><script type="text/javascript">var object = document.getElementById("object");object.onload = function(){var svgdoc;try {svgdoc = object.contentDocument;}catch(e){try{svgdoc = object.getSVGDocument();}catch(e){alert("SVG in object not support in your environment");}}if(!svgdoc) return;var r = svgdoc.rootElement;var square = svgdoc.getElementById("square");square.onclick = function(){var width = parseFloat(square.getAttributeNS(null,"width"));width -= 50;square.setAttributeNS(null,"width",width);var color = square.getAttributeNS(null,"fill");if(color == "bule"){square.setAttributeNS(null,"fill","yellow");square.setAttributeNS(null,"stroke","green");}else{square.setAttributeNS(null,"fill","bule");square.setAttributeNS(null,"stroke","red");}}}</script></body></html>
怎通過JS擷取HTML中iframe中的SVG整個文檔?
document.frames.iframe的name.document.....得到iframe的document對象
javascript 動態添加svg元素問題
給你點建議吧, 畫圖和載入是兩個步驟,
1。映像可以儲存為xml格式, svg格式, 或者存在資料庫中都可以,可以通過js把其轉換成為對象, 例如xml可以通過dom對其進行操作.最方便的還是json格式的資料, 直接轉為對象
2。畫圖, 可以把畫點, 線 形狀封裝成不同的函數, 通過和頁面事件關聯, 來操作, 可以參考JsxGraph
3. HTML5 圖形功能很強大