开发者

Error when trigger click event in IE6/IE7 (jquery)

开发者 https://www.devze.com 2023-01-21 17:52 出处:网络
I have this code: $(\"#boxId ul li a:eq(0)\").click(); Works ok in IE8 and FF, but I\'m getting error in IE6 and IE7.

I have this code:

$("#boxId ul li a:eq(0)").click();

Works ok in IE8 and FF, but I'm getting error in IE6 and IE7.

"Object doesn't support this property or method"

Someone knows why?

Obs:

$("#boxFoto 开发者_开发问答ul li a:eq(0)").size(); // returns '1'


There's no reason for jQuery's click() to fail on IE. I think the click event is actually triggered, but:

  • You have set an onclick handler on the hyperlink, and it tries to access a property or a method that's undefined under IE, or

  • You have an href="javascript:....." attribute on the hyperlink that has the same problem as above.


I found the error.

My code creates HTML dinamically, using this:

a.setAttribute("onclick","return false");

I changed to

a.onclick = function(){return false;};

And now works!


IE6/IE7 were returning the string "return false" in jquery code, not the function(){return false}. Somewhere in jquery code, I was getting "return false".apply(....., .....), that was the cause of the error Object doesn't support this property or method.

0

精彩评论

暂无评论...
验证码 换一张
取 消