3
我想使用下面的JavaScript代码将svg图形嵌入到我的页面中,但是当我在Android手机上使用Android默认浏览器命名为“Internet”版本5.8时,圆圈正在显示,但文字没有显示出来。它在其他浏览器上运行良好,但我担心它可能不会在某些Safari浏览器上显示。我在这里做错了什么?请注意,当我复制并粘贴输出svg代码到我的源文件并打开它时,文本将显示出来,所以我非常肯定JavaScript有一些问题。在Android浏览器中未显示SVG文本元素
var svgtag=document.createElementNS('http://www.w3.org/2000/svg','svg');
svgtag.setAttribute('height','500');
svgtag.setAttribute('width','500');
document.getElementById("piechart").appendChild(svgtag);
var circle=document.createElementNS('http://www.w3.org/2000/svg','circle');
circle.setAttribute('cx','250');
circle.setAttribute('cy','250');
circle.setAttribute('r','200');
circle.setAttribute('fill','#999');
svgtag.appendChild(circle);
var sample=document.createElementNS('http://www.w3.org/2000/svg','text');
sample.setAttribute('x','250');
sample.setAttribute('y','250');
sample.setAttribute('font-size','12');
sample.setAttribute('fill','#000');
sample.innerHTML='someting';
svgtag.appendChild(sample);
使用createTextNode代替innerHTML工作!非常感谢 – dshukertjr