简体   繁体   English

从动态生成的下拉列表中获取值

[英]get values from dynamically generated drop down

I'm trying to get all selected values from dropdown that is being populated after accessing some value from first select box ( ajax call). 我正在尝试从第一个select boxajax调用)访问某些值后,从正在填充的dropdown中获取所有selected值。

here what I've tried so far, 这是我到目前为止尝试过的

$(document).on('change', '#modal', function(){
    obj.push($('#modal').val());
});
console.log(obj);

#modal is the id of newly populated select box. #modal是新填充的select框的id

#make is the id of main select . #make是main selectid

I've tried these two as well 我也尝试过这两个

$('#make').on('change', '#modal', function(){

and

$('#modal').on('change', '#modal', function(){

but no luck by far 但到目前为止没有运气

PS. PS。 I'm using select2 我正在使用select2

You can retrieve the selected values from your #modal select in your ajax success callback after populating the select. #modal select ,您可以从ajax success callback #modal select中检索selected值。

For example http://jsfiddle.net/99hacq59/ 例如http://jsfiddle.net/99hacq59/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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