列出jQuery中的所有直播活动 [英] List all live events in jQuery
本文介绍了列出jQuery中的所有直播活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在jQuery中找到哪些事件与特定元素的实时绑定?
How could I find in jQuery what events are bound with live for a particular element?
假设我有一个函数, randomFunction
,从函数数组中返回一个随机函数。如何找到哪个函数绑定到某个元素?
Say I have a function, randomFunction
, that returns a random function from an array of functions. How can I find which function has been bound to a certain element?
var arrayOfFunctions = []; //a whole bunch of functions
function randomFunction(array){}; //returns one of those functions
$('#certain_element').live('click', randomFunction(arrayOfFunctions));
与 live
for $('#certain_element')
?
推荐答案
好吧,想通了。
对于单击
事件,对于 $('#certain_element')
,将每个绑定的索引记录到console:
Alright, figured it out.
For a click
event, for $('#certain_element')
, logging each binding's index to the console:
var relevantHandlers = $.map($(document).data('events').live, function(value){
if(value.origType == 'click' && value.selector == '#certain_element'){
return value.handler;
}
}; //all handlers for #certain_element bound to click by live.
$.each(relevantHandlers, function(){
console.log("the index is: " + $.inArray(this, arrayOfFunctions));
});
这篇关于列出jQuery中的所有直播活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文