繁体   English   中英

SVG文本元素未在Android浏览器中显示

[英]SVG text element not showing in android browser

我正在尝试使用下面的javascript代码将svg图形嵌入到我的页面中,但当我在我的手机上使用Android的默认浏览器名为“Internet”版本5.8查看网页时,圆圈正在显示,但文本未显示起来。 它在其他浏览器上运行良好,但我担心它可能不会出现在某些Safari浏览器上。 我在这做错了什么? 请注意,当我将输出svg代码复制并粘贴到我的源文件中并打开它时,文本会显示出来,所以我很确定javascript存在一些问题。

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);

创建文本节点的常用方法是via

text = document.createTextNode("someting");
sample.appendChild(text);

而不是innerHTML

这应该适用于Android的默认浏览器,并且也可以在其他任何地方使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM