JavaScript - onClick to get the ID of the clicked button

前端 未结 16 1459
名媛妹妹
名媛妹妹 2020-11-22 05:44

How do find the id of the button which is being clicked?


16条回答
  •  日久生厌
    2020-11-22 06:32

    This is improvement of Prateek answer - event is pass by parameter so reply_click not need to use global variable (and as far no body presents this variant)

    function reply_click(e) {
      console.log(e.target.id);
    }
    
    
    

提交回复
热议问题