2014-09-19 4 views
0

Je veux créer svg en utilisant javascript dans IE9, donc j'ai utilisé la méthode document.craeteElementNS. Cela fonctionne bien dans un autre navigateur mais pas IE9. Puis-je savoir pourquoi? Voici une documentation indiquant que la méthode devrait fonctionner avec IE9, http://msdn.microsoft.com/en-us/library/ie/ff975213%28v=vs.85%29.aspx Mais quand je l'ai essayé, je ne sais pas, puis-je savoir pourquoi?
Result: It doesn't shows the polygon on the page that it should be, it just convey a blank pagedocument.createElementNS méthode ne fonctionne pas sur 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

Qu'est-ce exactement "ne fonctionne pas"? Avez-vous une erreur? Quel est le problème? "Cela ne marche pas" est la pire description d'erreur, car elle ne transmet aucune information. Que votre code ne fonctionne pas est déjà implicite en postant ici. –

+0

Il ne montre pas le polygone, il n'y a rien sur la page. Désolé pour le manque d'info – dramasea

+0

Qu'avez-vous fait pour déboguer le problème? –

Répondre

-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

Pourquoi jouez-vous au jeu «repérez la différence» plutôt que de fournir des explications utiles? Qu'est-ce qui se passe avec le code que vous avez publié? Comment cela résout-il le problème du PO? –