HTML:
<select data-placeholder="Choose a Travel Agency..." class="chosen-select fc-inputbox travel-agency-dropdown" id="travel_agency_id">
... foreach
</select>
使用Javascript:
var data = {
id: row.find('td:first-child').text().trim(),
travel_agency_name: row.find('td:nth-child(2)').text().trim(),
};
var select_travel_agency = $('.travel-agency-dropdown:first').clone().attr('id', 'travel-agency-id-'+data.id).val(data.travel_agency_name).trigger("chosen:updated");
我已经创建了旅行社,我想要的是在设置代理商的SELECT默认值时更新它。我克隆它的原因是我获取数据而不调用另一个GET
答案 0 :(得分:0)
你能使用jQuery的change
函数吗?
例:
<select class="target">
<option value="option1" selected="selected">Option 1</option>
<option value="option2">Option 2</option>
</select>
$( ".target" ).change(function() {
alert( "Handler for .change() called." );
});
所以你只需要写:
var clonedSelect = $('#travel-agency-id-'+data.id);
clonedSelect.change(function(){alert('second select changed his value to ' + clonedSelect.val());});