ITPub博客

首页 > 应用开发 > Java > List all javascript events wired up on a page using jquery

List all javascript events wired up on a page using jquery

原创 Java 作者:pyoracle 时间:2011-04-20 13:55:37 0 删除 编辑

(function($) {
$.eventReport = function(selector, root) {
var s = [];
$(selector || '*', root).andSelf().each(function() {
var e = $.data(this, 'events');
if(!e) return;
s.push(this.tagName);
if(this.id) s.push('#', this.id);
if(this.className) s.push('.', this.className);
for(var p in e) s.push('n', p);
s.push('nn');
});
return s.join('');
}
$.fn.eventReport = function(selector) {
return $.eventReport(selector, this);
}
})(jQuery);

[@more@]
// all events
alert
($.eventReport());// just events on inputs
alert
($.eventReport('input')); // just events assigned to this element
alert
($.eventReport('#myelement')); // events assigned to inputs in this element
alert
($.eventReport('input', '#myelement'));
alert
($('#myelement').eventReport('input')); // same result// just events assigned to this element's children
alert
($('#myelement').eventReport());
alert
($.eventReport('*', '#myelement'); // same result

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25556693/viewspace-1048918/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Java编码测试
请登录后发表评论 登录
全部评论

注册时间:2011-03-19

  • 博文量
    13
  • 访问量
    8776