【问题标题】:How to fix Window.getComputedStyle is not an object error如何修复 Window.getComputedStyle 不是对象错误
【发布时间】:2014-02-20 05:48:44
【问题描述】:

我正在尝试使用可在以下位置获得的 Draggabilly https://github.com/desandro/draggabilly

它在 html 中运行良好。现在,当我尝试将其添加到 wordpress 中时。我在 firebug 控制台中收到以下错误。

TypeError: Argument 1 of Window.getComputedStyle is not an object.
return s.getComputedStyle(t, null)

这里是一个js文件的链接 http://draggabilly.desandro.com/draggabilly.pkgd.min.js

【问题讨论】:

  • 您是否查看了调试器或console.log(t) 中的t 是什么?这似乎是显而易见的第一步,然后回顾一下您如何填充 t 以了解为什么它没有正确设置。
  • 感谢您的回复。我让它工作了。我刚刚在 wordpress 中复制了完整的演示 html 代码。
  • 在 d3.js 中,如果你尝试在一个不存在的 dom 对象上进行选择,你会得到这个错误。
  • @Incodeveritas 感谢您的评论 - 虽然我没有使用 D3,但您让我找到了解决方案。

标签: javascript jquery jquery-ui drag-and-drop getcomputedstyle


【解决方案1】:

你调用了两次 init。浏览您的代码并删除一个实例。

【讨论】:

    【解决方案2】:

    我在用 IE8 测试我的项目时收到了这个错误:终于很明显了,这个方法不适用于 IE 8!

    Error: Object doesn't support this property or method at: http://...
    

    我收到了支持此方法的 FF 的此错误,但我忘记将 window 更改为我的框架窗口对象!

    console.log(getComputedStyle(window.document.querySelector('.tip > .tip.top'), ':after').getPropertyValue('left'));
    TypeError: Argument 1 of Window.getComputedStyle is not an object.
    at: http://...
    

    请注意,即使您的window 对象正常但querySelector 没有返回任何内容,也会弹出上述错误! (我怀疑是你的情况)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 2022-07-10
      • 2019-10-04
      • 1970-01-01
      相关资源
      最近更新 更多