How to get the caller event and dom element id

前端 未结 1 1036
长发绾君心
长发绾君心 2020-12-15 18:54




        
相关标签:
1条回答
  • 2020-12-15 19:39

    An event object is passed to the Hello function automatically. You need to receive it as an argument and then do some cross-platform work to grab the element. A JS framework will help you out here.

    function Hello(e){
        var caller = e.target || e.srcElement;
        console.log( caller );
    }
    

    EDIT
    +1 Andrew's comment below. Use addEventListener and attachEvent for best practice.

    0 讨论(0)
提交回复
热议问题