何取消在lubricmonkey中的jquery事件处理程序的绑

何取消在lubricmonkey中的jquery事件处理程序的绑

本文介绍了我如何取消在lubricmonkey中的jquery事件处理程序的绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("p").click(function(){alert('clicked')});

$("p").unbind('click');

在润滑脂猴子中,单击事件不会解除绑定.我相信,这是由于lubricmonkey的安全模型从XPCNativeWrapper的第一行包装了关联的事件对象,导致第二行无法查找"它.但是,我似乎找不到解决方法.有什么建议吗?

Within greasemonkey the click event does not unbind. I believe this is caused by greasemonkey's security model wrapping the associated event object from the first line in XPCNativeWrapper, causing the second line to be unable to "find" it. However, I can't seem to find a workaround. Any suggestions?

更新:以下内容在油脂猴子中确实起作用.因此,我仍然认为这是XPCNativeWrapper的问题,我找不到解决方法.

UPDATE: Something like the following does work in greasemonkey. So I'm still thinking it's an XPCNativeWrapper issue that I can't find a way to resolve.

$("p").click(function(){alert('clicked'); $(this).unbind('click')});

推荐答案

我认为在调用unbind()函数之后添加了jQuery click事件.这就是下面的代码起作用的原因.

I think jQuery click events are added after calling unbind() function. This is why the following code works.

$("p").click(function(){alert('clicked'); $(this).unbind('click')});

在您的函数中经过了一段时间,直到您单击警报按钮,然后单击确定"后,unbind()函数才起作用.

Some time elapses in your function until you click the alert button and unbind() function works after you click OK.

这是我测试过的解决方案:

Here is a solution I have tested:

function removeClick() {
    $("p").unbind('click');
}

var initTimeout = setTimeout(function() { removeClick(); }, 1000);


如果您不喜欢在润滑脂脚本中使用超时或间隔,则可以将鼠标悬停事件添加到p元素中以删除点击.


If you don't like using timeouts or intervals in a greasemonkey script, you can add mouseover event to your p elements to remove the click.

$("p").mouseover(function(){
    $(this).unbind('click');
});

这篇关于我如何取消在lubricmonkey中的jquery事件处理程序的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 06:46