javascript – jQuery live(‘click’)点击右键单击

我注意到jQuery中的live()函数一个奇怪的行为:
<a href="#" id="normal">normal</a>
<a href="#" id="live">live</a>

$('#normal').click(clickHandler);
$('#live').live('click',clickHandler);

function clickHandler() {
    alert("Clicked");
    return false;
}

直到你右键单击“直播”链接并且它触发处理程序,然后才显示上下文菜单,这很好.在“正常”链接上,事件处理程序根本不起作用(如预期).

我已经能够通过将处理程序更改为这个来解决它:

function clickHandler(e) {
    if (e.button != 0) return true;
    // normal handler code here
    return false;
}

但是,对于所有的事件处理程序来说,这真的很麻烦.有什么更好的方法让事件处理程序只像普通的点击处理程序一样发火吗?

解决方法

这是一个 known issue

It seems like Firefox does not fire a
click event for the element on a
right-click,although it fires a
mousedown and mouseup. However,it
does fire a click event on document! Since .live catches
events at the document level,it sees
the click event for the element even
though the element itself does not. If
you use an event like mouseup,both
the p element and the document
will see the event.

您的解决方法是您现在可以做的最好的.它似乎只影响Firefox(我相信它实际上是Firefox中的一个bug,而不是jQuery本身).

另见this question昨天问.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


jQuery表单验证提交:前台验证一(图文+视频)
jQuery表单验证提交:前台验证二(图文+视频)
jQuery如何实时监听获取input输入框的值
JQuery怎么判断元素是否存在
jQuery如何实现定时重定向
jquery如何获取复选框选中的值
jQuery如何清空form表单数据
jQuery怎么删除元素节点
JQuery怎么循环输出数组元素
jquery怎么实现点击刷新当前页面
怎么用jquery实现文字左右展开收缩效果
jquery怎么删除html属性
如何用jquery实现图片翻转效果
jquery怎么删除样式属性
jquery如何获取当前元素的位置
如何用jquery实现点击展开收缩效果
jquery怎么实现点击隐藏显示效果
jQuery如何获取当前页面url
jQuery怎么获取鼠标的位置坐标
简洁易懂的jQuery:HTML表单与jQuery