get all elements with onclick in them?

后端 未结 6 1326
灰色年华
灰色年华 2020-12-19 15:32

I am looking for a way to list all elements that have onclick event on a page.

6条回答
  •  生来不讨喜
    2020-12-19 16:20

    This is fairly easy if the traditional/old school method of event handler attachment is used (the following code is untested).

    var getEventHandlers = function(nodes, eventType) {
        var handlers = [], h;
    
        for ( var i=0, l=nodes.length; i

    Use:

    console.log(getEventHandlers($("*"), "onclick"));
    console.log(getEventHandlers($(".some-class"), "onclick"));
    

提交回复
热议问题