我想在IE9中使用javascript創建svg,所以我使用了document.craeteElementNS方法。它適用於其他瀏覽器,但不是IE9。我能知道爲什麼嗎?這裏是一個文件,說明該方法應該與IE9, http://msdn.microsoft.com/en-us/library/ie/ff975213%28v=vs.85%29.aspx 一起工作但是當我嘗試了它,它不,我可以知道爲什麼嗎? Result: It doesn't shows the polygon on the page that it should be, it just convey a blank page
document.createElementNS方法不能在IE9上工作
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(window).load(function(){
var myDiv = document.getElementById("myDiv");
var mySVG = document.createElementNS("http://www.w3.org/2000/svg", "svg");
mySVG.setAttribute("height","210");
mySVG.setAttribute("width","500")
myDiv.appendChild(mySVG);
var myPolygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
myPolygon.setAttribute("style","fill:lime;stroke:purple;stroke-width:1");
myPolygon.setAttribute("points","200,10 250,190 160,210");
mySVG.appendChild(myPolygon);
});
</script>
</head>
<body>
<div id="myDiv">
</div>
</body>
</html>
究竟 「不工作」?你有錯誤嗎?有什麼問題? 「它不起作用」是最糟糕的錯誤描述,因爲它沒有傳達任何信息。你的代碼不起作用已經暗示你在這裏發佈。 – 2014-09-19 17:30:40
它不顯示多邊形,頁面上沒有任何內容。對不起,缺少信息 – dramasea 2014-09-19 17:33:30
您是如何解決問題的? – 2014-09-19 17:34:16