JavaScript - onClick to get the ID of the clicked button

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

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


16条回答
  •  猫巷女王i
    2020-11-22 06:11

    If you don't want to pass any arguments to the onclick function, just use event.target to get the clicked element:

    
    
    
    
    function reply_click()
    {
        // event.target is the element that is clicked (button in this case).
        console.log(event.target.id);
    }
    

提交回复
热议问题