jQuery - Dynamically Create Button and Attach Event Handler

前端 未结 5 1064

I would like to dynamically add a button control to a table using jQuery and attach a click event handler. I tried the following, without success:

$(\"#myBut         


        
5条回答
  •  醉梦人生
    2020-12-13 13:16

    You can either use onclick inside the button to ensure the event is preserved, or else attach the button click handler by finding the button after it is inserted. The test.html() call will not serialize the event.

提交回复
热议问题