简体   繁体   中英

Change Combobox Option using jQuery

When I produce Combox by jQuery I can't change the selected option by using jQuery. if I manually produce a combo-box on an html page I can change by using this code:

 $(#role).val(2)

But in jQuery I can't.

This is my code:

 $("div[class='row'][itemid='1']").after('<div class="row" itemid="' + itemid_ + '"><div class="col-xs-4" itemid= "' + itemid_ + '"><select id="modul' + itemid_ + '" itemid="' + itemid_ + '"  ></select></div><div class="col-xs-4" itemid="' + itemid_ + '"><select id="role' + itemid_ + '"></select></div><div class="col-xs-4" itemid="' + itemid_ + '"><input class="knp" type="button" itemid="' + itemid_ + '" onclick=DeleteElement(' + itemid_ + ') value="Удалить"/><input class="knp' + itemid_ + '" type="button" onclick=AddElement(' + itemid_ + ') itemid="' + itemid_ + '" value="Добавить"/></div></div>')

function getModul(modul,itm) {
 $(modul).append('<option value="' + jsondata_1[i].MODUL_ID + '">' + jsondata_1[i].MODUL_NAME + '</option>')
}

After this code I can't change the selected value of the produced combo-box.

Your combobox's ID is modul - so to select it with jQuery and change it's value you'd need to use $("#modul").val(2)

You can test this using the console inspector of Chrome

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