每天一個JavaScript執行個體-SVG中的javaScript展示,javascript-svg

來源:互聯網
上載者:User

每天一個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>

幫你完完整整改過了!!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.