Events triggered by dynamically generated element are not captured by event handler

后端 未结 5 2115
失恋的感觉
失恋的感觉 2020-11-21 05:46

I have a

with id=\"modal\" generated dynamically with the jQuery load() method:

$(\'#modal\').load(\'handl         


        
5条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 06:43

    If you need to capture changes for all of the form elements, particularly select boxes, I know they are not mentioned here, but it is helpful to know, use the following code:

    $(document).on('change', ':input', function () {
       alert('value of ' + $(this).attr('name') + ' changed')
    });
    

    This should cover all input, textarea, select, checkbox, radio, etc.

提交回复
热议问题