2013-05-13 12 views
3

我想提示添加到一个独立的SVG文件时,我“‘在’操作风格无效”错误接收,但它返回以下错误:试图工具提示功能添加到独立的SVG文件

TypeError: invalid 'in' operand style 
[Break On This Error] 

if (name in style) { 

以下jQuery的2.0.0功能:

// return a css property mapped to a potentially vendor prefixed property 
function vendorPropName(style, name) { 

    // shortcut for names that are not vendor prefixed 
    if (name in style) { 
     return name; 
    } 

    // check for vendor prefixed names 
    var capName = name.charAt(0).toUpperCase() + name.slice(1), 
     origName = name, 
     i = cssPrefixes.length; 

    while (i--) { 
     name = cssPrefixes[ i ] + capName; 
     if (name in style) { 
      return name; 
     } 
    } 

    return origName; 
} 

如果我通过HTML页面呈现SVG文件,它工作正常。但我需要它作为一个纯SVG工作,并且无法做到这一点。

下面是HTML(作品)和SVG(不)的相同页面。 tooltip插件被称为tooltipster(由Caleb Jacob开发)。

编辑:看来这个问题是错误地陈述。下面是从keith-wood.name相关报价:

The SVG DOM is different to the HTML DOM for which jQuery was designed. In particular, any attributes that can be animated are stored as objects instead of plain strings. This includes the class attribute. Thus, jQuery's functions that work with classes don't work on SVG nodes.

原来的jQuery版本的若干修改可以在尝试解决这个问题在互联网上找到,但他们又不能与最新版本的工作jQuery插件。

我不确定这是否使问题得到解答。

+2

'name in style'只在style是字典时才起作用。你可能想要'if(style.indexOf(name)> = 0)'而不是 – karthikr 2013-05-13 17:09:29

+0

当它改为'if(style.indexOf(name)> = 0时返回'TypeError:style.indexOf不是函数' {return name; '[(pastebin,line 6037)](http://pastebin.com/ThQjxch0)。我试着玩括号并使用.toString()来修复它,但不能。在qTip上也有[bug](https://bugs.launchpad.net/jquery/+bug/364750),'type.indexOf不是一个函数',但我不确定它在这里是否有任何相关性。 – 2013-05-13 21:35:02

回答