onclick 事件在 IE8 中被破坏

发布于 2024-08-18 23:45:17 字数 726 浏览 3 评论 0原文

我有以下代码片段,可以按预期工作:

<a href="http://google.com" onclick="return false;">Will go to google</a>

单击 href 不会带我去谷歌。

但是...如果我包含 JQuery 1.4 并将实时单击事件连接到页面上的任何内容(无论它是否存在),则此不相关的事件处理程序将停止在 IE 中按预期工作(并继续在 Firefox 和 Chrome 中工作)。返回 false 会被忽略,点击链接会将您带到谷歌。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type='text/javascript'>
          //<![CDATA[
    $(document).ready(function() {
         $(".not-here").live("click", function() {alert("hi"); return false; });
    });
          //]]>
 </script>

这是怎么回事?我在 JQuery 1.4 版本中遇到过错误吗?

I have the following snippet which works as expected:

<a href="http://google.com" onclick="return false;">Will go to google</a>

Clicking on the href does not take me to google.

But... if I include JQuery 1.4 and wire up a live click event to anything on the page (whether it exists or does not) this unrelated event handler stops working as expected in IE (and continues to work in firefox and chrome). Return false is ignored and instead clicking on the link takes you to google.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type='text/javascript'>
          //<![CDATA[
    $(document).ready(function() {
         $(".not-here").live("click", function() {alert("hi"); return false; });
    });
          //]]>
 </script>

Whats going on? Have I come across a bug in the JQuery 1.4 release.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩世 2024-08-25 23:45:17

是的,这是 JQuery 1.4 版本中的一个错误。它会影响任何使用现场活动的人。

这是 John 于 2010 年 1 月 24 日修补。它已在 JQuery 中修复1.4.1 于 2010 年 1 月 26 日发布。

请参阅:http://dev.jquery.com /票/5835

Yes this is a bug in JQuery 1.4 Release. It affects anyone using the live events.

It was patched by John on the 24th of Jan 2010. It has been fixed in JQuery 1.4.1 which was released on the 26th of Jan 2010.

See: http://dev.jquery.com/ticket/5835

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文