【发布时间】:2018-01-29 11:00:15
【问题描述】:
html
<label>Customer PO</label>
<select name="Customer_PO" class="form-control" id="Customer_PO" >
<option value="" >Customer PO</option>
</select>
-------------
jquery
$('body').on('click','#Customer_PO',function(e){
id_tosend=$(this).attr("id").toString();
var cust_id=$('#Customer_list').val();
var a=$('#'+id_tosend).select2({
ajax: {
url: 'ajax/report/inspection_report.php?cust_id='+cust_id,
dataType: 'json',
delay: 500,
data: function (params) {
var queryParameters = {
q: params.term
}
return queryParameters;
},
processResults: function (data) {
return {
results: data
};
},
cache:true
}
});
a.data('select2').dropdown.$dropdown.addClass("test");
$(this).select2('open');
});
我附加了 Select2 的插件。当我在表单中提交数据时,它显示为空值。我如何获取此值以在 ajax 方法中设置选定的初始值。
【问题讨论】:
-
我用这种方式搜索,但它没有改变选定的值,我在 ajax 中找到了这种方式,它不是完美的展示,如果你知道这一点...
标签: javascript jquery ajax jquery-selectors jquery-select2