【问题标题】:jQuery TypeError: a.style is undefined when loading svg file in Firefox 20.0jQuery TypeError:在 Firefox 20.0 中加载 svg 文件时未定义 a.style
【发布时间】:2013-03-29 12:17:15
【问题描述】:

我使用 SVG 文件。 SVG 文件具有 xlink-ed jQuery。

在 Firefox 20.0 中打开 svg 文件时出现错误

TypeError: a.style 未定义

如果我在 Firefox 19 及更早版本中打开 svg 文件,则不会出现错误。

任何想法为什么带有 svg 的 jQuery 在 FF20.0 中不起作用?

我的 SVG 演示文件

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
     width="467" height="462">

  <rect x="80" y="60" width="250" height="250" rx="20"
      style="fill:#ff0000; stroke:#000000;stroke-width:2px;" />

  <rect x="140" y="120" width="250" height="250" rx="40"
      style="fill:#0000ff; stroke:#000000; stroke-width:2px;
      fill-opacity:0.7;" />

  <script
     xlink:href="http://code.jquery.com/jquery-1.9.1.js"
     id="script10"
     type="text/javascript" />
</svg>

【问题讨论】:

  • 与 jQuery 1.7.1、1.8.x 和 1.9.1 + svg 相同的问题。

标签: jquery firefox svg


【解决方案1】:

这是由于 jQuery 假设它基本上是在 HTML 文档中运行的。见http://bugs.jquery.com/ticket/13754

【讨论】:

    【解决方案2】:

    正如@Boris 在另一个答案中所说,这是由于 jquery 错误造成的。

    this link你可以看到更多关于它的信息。

    其中一个 cmets 建议如下(在 jquery-1.9.1 中):

    在 jquery-1.9.1 中,第 1321 行,更改为:

    if ( !all || !a || !all.length ) {
    

    这个:

    if (!all || !a || !all.length || !a.style) {
    

    他的解释:

    这应该会导致 jQuery.support 函数返回 {}(一个空的 对象),就像在其他浏览器上一样。在 FF19 中,"!a" 计算 为真。在 FF20 中,“!a”的计算结果为 false,但 a.style 未定义。所以 检查 !a.style 应该避免这里的错误。

    这解决了我的问题!

    注意:更改第三方代码不是一个好习惯,但我目前没有找到更好的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 2018-06-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多