我正在使用别人不久前编写的HTML/jQuery页面。为了进行调试,我需要找到在页面加载时为任何元素触发的所有.blur()事件。
我可以使用以下代码将事件绑定到所有元素:
$("*").each(function() {
$(this).blur(function() {
alert(this);
});
});但是,这不会起作用(即使我可以在页面加载之前运行它),因为页面上的脚本无论如何都会重新绑定.blur()事件。
有没有办法让我看到在页面加载时执行了哪些.blur()事件?我想我也许能够在运行时覆盖.blur()内部jQuery函数,而不会被模糊事件绑定覆盖,但不确定这是否可能。
发布于 2012-01-19 18:04:57
使用.on('blur', '*', ...) (jQuery 1.7+)将blur事件绑定到document:
$(document).on('blur', '*', function(e) {
e.stopPropagation(); // Otherwise, many alerts will pop up for each event
alert(this);
});如果您没有jQuery 1.7+,请改用delegate:
$(document).delegate('*', 'blur', function(e) {
e.stopPropagation(); // Otherwise, many alerts will pop up for each event
alert(this);
});https://stackoverflow.com/questions/8923863
复制相似问题