每天一個JavaScript執行個體-SVG中的javaScript展示,javascript-svg
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" version="1.1"xmlns="http://www.w3.org/2000/svg"><script type="text/javascript"><![CDATA[window.onload = function(){var square = document.getElementById("square");square.onclick = function(){var color = this.getAttribute("fill");console.log(color);if(color =="#f00"){this.setAttribute("fill","#00f");}else{this.setAttribute("fill","#f00");}}}]]></script><rect id= "square" x="10" y="10" width="400" height="400"style="stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" fill="#00f"/></svg>
javascript 動態添加svg元素問題
給你點建議吧, 畫圖和載入是兩個步驟,
1。映像可以儲存為xml格式, svg格式, 或者存在資料庫中都可以,可以通過js把其轉換成為對象, 例如xml可以通過dom對其進行操作.最方便的還是json格式的資料, 直接轉為對象
2。畫圖, 可以把畫點, 線 形狀封裝成不同的函數, 通過和頁面事件關聯, 來操作, 可以參考JsxGraph
3. HTML5 圖形功能很強大
一個javascript指令碼的執行個體
<html>
<head>
(這裡按照圖示填寫 標題列 代碼)
<script language= "javascript">
function test1(){
if(document.forml.text1.value=="")
alert("您沒有輸入任何資料,請再重新輸入一次! ");
else
alert( +" ! 您已輸入完成!");
}
</script>
</head>
<body>
<form name="forml">
請輸入姓名<input type="text" name="text1" value=""><br>
<input type="button" name="button1" value="輸入測試" onclick="test1()">
</form>
</body>
</html>
幫你完完整整改過了!!