可以绑定并传递参数给回调监听器来识别类型
$(document).click(function (type) {
console.log(type)
}.bind(this,"i-am-click"));
$(document).click(function (type) {
console.log(type)
}.bind(this,"i-am-another-click"));
var events = $._data(document, "events");
console.log(events);
UPDATE
确定具体的事件对象在你的事件数组,你可以做下面的技巧。
$(document).click(
(function(){
var fn = function(){ // Your callback function
console.log('i-am-click');
};
fn.event_id=1; // Adding id to the callback.
return fn; // returning the function after adding id
})()
);
$(document).click(
(function(){
var fn = function(){ // Your callback function
console.log('i-am-another-click');
};
fn.event_id=2; // Adding id to the callback.
return fn; // returning the callback function after adding id
})()
);
var events = $._data(document, "events");
// Find the events in the event array using filter
// This will return an array of match event with id in events array
events.click.filter(function(ev){return ev.handler.event_id==1;}); // event id you are looking for
什么会事件“存在”是什么意思?如果你使用这个你想写的信息显示代码,这将会有所帮助。 –
这听起来像是一个XY问题。为什么你需要这样做? –
我有一个脚本挂起了一个单击事件。并且在我需要检查这个事件后是否存在 –