JQuery assign events to buttons

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

I have 50 dynamically generated HTML buttons as follows:




        
8条回答
  •  无人及你
    2020-12-11 23:51

    I think it will be better if you use a common class name for all and handle click event by that class name.

    $('.classname').click(function(){
        //`enter code here`
    });
    

    Or you can handle event by tag name:

    $('button').click(function(){
        //'enter code here'
    });
    

    This method might effect the function of other buttons which are not included in the group of 50 buttons.

提交回复
热议问题