2013-04-07 76 views
2

我使用SVG文件。 SVG文件有xlink-ed jQuery。jQuery TypeError:在Firefox中加载svg文件时未定义a.style 20.0

当在Firefox 20.0打开SVG文件,我得到错误

TypeError: a.style is undefined

如果我在Firefox中打开19和旧版本SVG文件,没有出现错误。

任何想法为什么jQuery与svg不工作在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> 
+1

与jQuery 1.7.1,1.8.x和1.9.1 + svg相同的问题。 – azendh 2013-04-08 09:26:12

回答

0

正如@Boris在另一个答案中所说的,这是由于jquery bug引起的。

this link中,您可以看到更多关于它的信息。

之一的意见提出了以下(在jquery的-1.9.1):

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

jQuery中-1.9.1,1321线,从变化这样的:

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

他的解释:

This should cause the jQuery.support function to return {} (an empty object), as it seems to do on other browsers. In FF19, "!a" evaluates to true. In FF20 "!a" evaluates to false, but a.style is undefined. So checking for !a.style should avoid the error here.

这解决了我的问题!

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