Internet explorer Internet explorer中svg文本中的空白
我试图通过Snap.svg在svg中追加/写入文本。下面的代码在chrome、firefox、opera和edge中运行良好,但在Internet Explorer中不起作用。我曾尝试将字符集作为utf8放在html文件的meta标记中,但仍然不起作用Internet explorer Internet explorer中svg文本中的空白,internet-explorer,svg,whitespace,snap.svg,Internet Explorer,Svg,Whitespace,Snap.svg,我试图通过Snap.svg在svg中追加/写入文本。下面的代码在chrome、firefox、opera和edge中运行良好,但在Internet Explorer中不起作用。我曾尝试将字符集作为utf8放在html文件的meta标记中,但仍然不起作用 如果将LeSES2作为参数传递,则Internet Explorer会考虑为正常字符串。 var lines1 = ["a b", "c d", "e f"]; var lines2 = ["a&am
如果将LeSES2作为参数传递,则Internet Explorer会考虑为正常字符串。
var lines1 = ["a b", "c d", "e f"];
var lines2 = ["a b", "c d", "e f"];
Snap("#svg").text(10, 0, lines).attr({
fill: "black",
fontSize: "18px"
}).selectAll("tspan").forEach(function(tspan, i) {
tspan.attr({
x: 0,
dy: 20
});
tspan.node.innerHTML = tspan.node.textContent.replace(/ /g,' ');
});
这是它的链接。
也许我的解决方案将有助于尝试添加此doctype声明,以解决Internet Explorer的问题。
也许我的解决方案将有助于尝试添加此doctype声明,以解决Internet Explorer的问题。在SVG元素上使用
innerHTML
。仅适用于最新的浏览器版本
使用textContent
,并使用等同于nbsp的unicode字符(ASCII 160),而不是HTML Latin1实体
var行=[“ab”、“cd”、“ef”]
Snap(“#svg”).text(10,0,行).attr({
填充:“黑色”,
字体大小:“18px”
}).selectAll(“tspan”).forEach(函数(tspan,i){
tspan.attr({
x:0,,
dy:20
});
tspan.node.textContent=tspan.node.textContent.replace(//g',\u00a0');
});代码>
在SVG元素上使用innerHTML
并不是普遍支持的。仅适用于最新的浏览器版本
使用textContent
,并使用等同于nbsp的unicode字符(ASCII 160),而不是HTML Latin1实体
var行=[“ab”、“cd”、“ef”]
Snap(“#svg”).text(10,0,行).attr({
填充:“黑色”,
字体大小:“18px”
}).selectAll(“tspan”).forEach(函数(tspan,i){
tspan.attr({
x:0,,
dy:20
});
tspan.node.textContent=tspan.node.textContent.replace(//g',\u00a0');
});代码>