I have JS code开发者_开发问答 like so:
var li = $("li[attribute=foo]");
if (li.length)
{
li.show("slow"); // Fails
}
I see:
Error: Object doesn't support this property or method
show()
with no arguments works.
Same for fadeIn()
or scrollUp()
. I've also noticed closest()
fail on another element. All these work in Firefox.
I'm suspicious that this is because the content in question is within an iframe (jquery itself is included in the outer page), but all other jquery in the iframe works, and from the IE debugger's point of view, the li exists and has a show method available with arguments.
Any ideas what's going wrong, or how to work around this, would be much appreciated.
As per the comments above, this was nothing to do with the version of jquery or the iframe, but was because of some JS on my page in the form:
Object.prototype.someCustomFunction = function( aObjects ) { ...}
It's worth sharing how I solved this in case it helps anyone. The secret was to get the full version of jquery, not the obfuscated and compressed one, so I could debug more easily what was going wrong in jquery.
What I found was that in Sizzle.filter
, jquery iterates like so:
for ( var type in Expr.filter ) {
if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
...
}
}
The point is that jquery is expecting to find ATTR
, CHILD
, CLASS
etc as the type
. But it also finds someCustomFunction
. And someCustomFunction
doesn't have an exec
, so it falls over.
The hack fix for now is to just introduce an empty exec
method for jquery to find. e.g.
Object.prototype.someCustomFunction.exec = function( expr ) {}
Longer term, I'll want to restrict someCustomFunction
to where it's actually required, rather than just Object
.
精彩评论