[英]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) : 您可以使用on()
的委托版本来on()
,并将事件委托给最接近的非动态父对象(使用下面示例中的文档):
$(document).on('change', '#mySelect', function() {
this.value = subgroup_id; //sets the value on change ????
});
Use the on() method - http://api.jquery.com/on/ 使用on()方法-http://api.jquery.com/on/
$('body').on('change', '#mySelect', function() {
// do stuff here
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.