IE10 d3.v3.js错误:无法获取未定义或空引用的属性"原型"

vaj*_*mar 19 d3.js internet-explorer-10

我的页面在IE9,Safari,Chrome和Firefox中完美加载.

但当它与IE10同步时,它会抛出错误: 无法d3.v3.js获取未定义或空引用的属性"原型":d3_window.CSSStyleDeclaration.prototype.

 try {
    d3_document.createElement("div").style.setProperty("opacity", 0, "");
  } catch (error) {
    var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
    d3_style_prototype.setProperty = function(name, value, priority) {
      d3_style_setProperty.call(this, name, value + "", priority);
    };
  }
Run Code Online (Sandbox Code Playgroud)

我不知道到底在做什么.

在try块中,即使setProperty方法,我们可以在调试器中看到d3_document.createElement("div").style 它抛出错误: 对象不支持属性或方法'setProperty'

在catch块中,它试图访问窗口的原型CSSStyleDeclaration,但这是未定义的.

使用d3.v3.js时,任何人都遇到了同样的问题

Lan*_*don 51

这可以通过以下方法修复DOCTYPE:

<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)

还有一个meta标签:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Run Code Online (Sandbox Code Playgroud)

没有这些,IE将进入怪癖模式,不明白是什么CSSStyleDeclaration.