Javascript global onclick listener

前端 未结 3 1590
余生分开走
余生分开走 2020-12-31 07:39

Is there a way to register a global onclick listener that will fire anytime an element is clicked? Need to also get the id of that element.

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 08:15

    document.addEventListener("click", function(evnt){
        console.log(evnt.target.id);
    });
    

提交回复
热议问题