简体   繁体   中英

How to bind .change() event in jquery to a dynamically generated html element

$("#mySelect").val(subgroup_id).change()

这里mySelect是动态生成的下拉列表

You'd do that by using the delegated version of on() , and delegate the event to the closest non-dynamic parent (using the document in the example below) :

$(document).on('change', '#mySelect', function() {
    this.value = subgroup_id; //sets the value on change ????
});

Use the on() method - http://api.jquery.com/on/

$('body').on('change', '#mySelect', function() {
    // do stuff here
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM