2014-09-19 4 views
0

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 pagedocument.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> 
+1

정확히 무슨 "작동하지 않습니다"
? 오류가 있습니까? 뭐가 문제 야? "작동하지 않는다"는 정보를 전혀 전달하지 않기 때문에 최악의 오류 설명입니다. 귀하의 코드가 작동하지 않는다는 것은 이미 귀하가 여기 게시 한 것을 의미합니다. –

+0

다각형이 보이지 않으며 페이지에는 아무 것도 없습니다. 죄송합니다. 정보가 부족합니다. – dramasea

+0

문제를 디버깅하기 위해 무엇을 했습니까? –

답변

-3

$(document).ready(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 obj = document.createElementNS("http://www.w3.org/2000/svg", "polygon"); 
 
    //obj.setAttributeNS(null, "cx", 100); 
 
    //obj.setAttributeNS(null, "cy", 50); 
 
    //obj.setAttributeNS(null, "r", 40); 
 
    obj.setAttributeNS(null, "stroke", "purple"); 
 
    obj.setAttributeNS(null, "stroke-width", 1); 
 
    obj.setAttributeNS(null, "fill", "lime"); 
 
    obj.setAttributeNS(null, "points", "200,10 250,190 160,210"); 
 
    mySVG.appendChild(obj); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> 
 
<div id="myDiv"></div>

+2

왜 도움이되는 설명 대신 "차이점 찾기"게임을하고 있습니까? 게시 한 코드는 무엇입니까? OP의 문제를 어떻게 해결할 수 있습니까? –

관련 문제