javascript - innerHTML 在 IE 10 中不起作用

标签 javascript html internet-explorer svg

我有 IE 10 和 svg 图像。在 svg 中,我将 TEXT 元素与

var newElement = function(name, attr) {
var svgNS = "http://www.w3.org/2000/svg";  
var tmp = document.createElementNS(svgNS, name);
for (k in attr) {
    if (k === 'style') {
        for (s in attr[k]) {
            tmp.style[s] = attr[k][s]; 
        }
    } else if (k === 'innerHTML') {
        console.log('Break 1('+typeof(attr[k])+')'+ attr[k]);
        console.log('Break 2: '+tmp.innerHTML);
        tmp.innerHTML = attr[k];
        console.log('Break 3: '+tmp.innerHTML);
    } else {
        tmp.setAttributeNS(null, k, attr[k]);
    }
}

console.log('Break 4: ');
console.log(tmp);
return tmp;

};

而且我无法在 IE 中看到放置的文本。在 FF 和 Chrome 中它工作正常。 在源代码中我可以看到空文本元素,但文本元素具有属性。

它是来自 IE 控制台的日志:

Break 1(string)Coś tam Marzec: 158
Break 2: undefined
Break 3: Coś tam Marzec: 158
Break 4: 
<text id="1135198_point_2_desc" font-size="11" visibility="hidden" text-anchor="middle" x="204.8182" y="209.68"></text>

Firefox 控制台:

Break 1(string)Legenda Pionowa
svg.html (wiersz 50)
Break 2:
svg.html (wiersz 51)
Break 3: Legenda Pionowa
svg.html (wiersz 53)
Break 4:
svg.html (wiersz 59)
<text x="0" y="130" text-anchor="middle" fill="#000000" transform="rotate(-90, 20, 130)">

而在 firefox 中,文本位于 TEXT 元素内

最佳答案

好的,我解决了我的问题。我用了https://code.google.com/p/innersvg/ 我将 innerHTML 替换为 innerSVG

关于javascript - innerHTML 在 IE 10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604693/

相关文章:

javascript - 如何触发绝对位置验证引擎功能来验证按钮单击时的字段?

javascript - 使用鼠标位置在网页上滚动 - 将鼠标悬停在侧面元素上

html - 增加html中td单元格的宽度和高度

javascript - 使文本在单击按钮时出现/消失

internet-explorer - 使用 PostMessage 和 ALT+T 以编程方式打开 F12 Internet Explorer 开发人员工具的工具菜单

internet-explorer - Google Analytics(分析)如何计算IE浏览器?

internet-explorer - 有没有办法将 Internet Explorer 设置转储到文本文件?

javascript - AngularJS 检测 Controller 中的浏览器后退按钮按下?

JavaScript 验证和重定向不起作用

javascript - Select2 initSelection 已弃用