Jquery .change() function not working with dynamically populated SELECT list

前端 未结 7 915
灰色年华
灰色年华 2020-12-05 14:13

I have a select field that is dynamically populated with an ajax call that simply returns all the HTML select options. Here is the part of the PHP that just echo\'s the sel

7条回答
  •  一整个雨季
    2020-12-05 14:25

    Just commented on your last question...Here's what I said:

    Use jQuery bind

    function addSelectChange() {
       $('select').bind('change', function() {
           // yada yada
       });
    } 
    

    Call addSelectChange in your ajax success function. It should do the trick. Take a look at jQuery live event too (for when you want to set events for all current and future DOM elements in a later project or something). Unfortunately the change event and a few others aren't yet supported with live. Bind is the next best thing

提交回复
热议问题