2

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

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

类型错误: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>
4

2 回答 2

2

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

于 2013-04-09T07:34:19.570 回答
0

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

此链接中,您可以看到有关它的更多信息。

其中一条评论建议如下(在 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 应该避免这里的错误。

这解决了我的问题!

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

于 2013-05-14T14:10:05.757 回答