JQuery assign events to buttons

前端 未结 8 841
小蘑菇
小蘑菇 2020-12-11 23:43

I have 50 dynamically generated HTML buttons as follows:




        
8条回答
  •  情书的邮戳
    2020-12-11 23:52

    if you have all the buttons inside of a container and you want the same function for all add the click handler to the container

    DEMO

    $("#container").on("click", function(e){
        if(e.target.type =="button")
        {
            alert(e.target.id);
        }
    });
    
    
    something

提交回复
热议问题