【问题标题】:I need compatible JavaScript code for document.createElementNS() in older versions of IE我需要旧版本 IE 中 document.createElementNS() 的兼容 JavaScript 代码
【发布时间】:2012-04-09 18:41:19
【问题描述】:

JavaScript 函数document.createElementNS() 在旧版本的 IE (6,7,8) 中不起作用?这个函数有没有兼容的代码,比如Arraycompatible map function老版本IE?

【问题讨论】:

  • 你具体指的是哪个版本的IE?
  • IE 不支持 svg,例如 6,7 和 8
  • 您能否发布使用并包含 document.createElementNS() 的 javascript 代码?如果可能的话,在jsfiddle.net 中。
  • var img = document.createElementNS("w3.org/2000/svg", "image"); img.setAttributeNS("w3.org/1999/xlink", "xlink:href", "move.png");
  • createElementNS的第一个参数是一个字符串。那里有一个不必要的分号 (;)。删除它。也适用于 setAttributeNS。

标签: javascript internet-explorer svg


【解决方案1】:

请查看以下 google 群组帖子。有一种解决方法可以帮助您: http://code.google.com/p/svgweb/issues/detail?id=625

解决方法(来自上面的链接):

window.onload = function() {
    function onCreateElementNsReady(func) {
        if (document.createElementNS != undefined) {
            func();
        } else {
            setTimeout(function() { onCreateElementNsReady(func); }, 100);
        }
    }

    onCreateElementNsReady(function() {
        var svg = document.createElementNS(svgns, 'svg');
        // ...
    });
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多