Capturing all the click event

前端 未结 10 1552
无人共我
无人共我 2020-12-14 08:46

I am thinking of to add a javascript function to capture all the click events inside a html page.

So I am adding a global function that govern

10条回答
  •  失恋的感觉
    2020-12-14 09:18

    I guess this simple code will work with jquery.

     $("a").click(function(){
        alert($(this).attr('href'));
    });
    

    Without JQuery:

    window.onclick = function(e) { 
    if(e.target.localName=='a')
        alert(e.target);
    };
    

    The above will produce the same result.

提交回复
热议问题