Javascript 选择2个版本。改用$element.val()“欢迎光临。虽然我们感谢您的回答,但如果它能在其他答案的基础上提供额外的价值,那就更好了。在这种情况下,您的答案不会提供额外的价值,因为Rajdip Khavad已经发布了该解决方案。如果之前的答案对你有帮助,
Javascript 选择2个版本。改用$element.val()“欢迎光临。虽然我们感谢您的回答,但如果它能在其他答案的基础上提供额外的价值,那就更好了。在这种情况下,您的答案不会提供额外的价值,因为Rajdip Khavad已经发布了该解决方案。如果之前的答案对你有帮助,,javascript,jquery,jquery-select2,Javascript,Jquery,Jquery Select2,选择2个版本。改用$element.val()“欢迎光临。虽然我们感谢您的回答,但如果它能在其他答案的基础上提供额外的价值,那就更好了。在这种情况下,您的答案不会提供额外的价值,因为Rajdip Khavad已经发布了该解决方案。如果之前的答案对你有帮助,你应该在你有足够的声誉后投票支持它。 <input id="remote" type="hidden" data-placeholder="Choose Something" /> var $remote = $(
选择2个版本。改用
$element.val()
“欢迎光临。虽然我们感谢您的回答,但如果它能在其他答案的基础上提供额外的价值,那就更好了。在这种情况下,您的答案不会提供额外的价值,因为Rajdip Khavad已经发布了该解决方案。如果之前的答案对你有帮助,你应该在你有足够的声誉后投票支持它。
<input id="remote" type="hidden" data-placeholder="Choose Something" />
var $remote = $('#remote');
$remote.select2({
allowClear: true,
minimumInputLength: 2,
query: function(options){
$.ajax({
dataType: 'json',
url: myURL + options.term,
error: function(jqXHR, textStatus, errorThrown){
smoke.alert(textStatus + ": server returned error on parsing arguments starting with " + options.term);
},
success: function(data, textStatus, jqXHR){
var results = [];
for(var i = 0; i < data.length; ++i){
results.push({id: data[i].id, text: data[i].name});
}
options.callback({results: results, more: false});
}
});
}
});
Uncaught Error: cannot call val() if initSelection() is not defined
$remote.select2('data', {id: null, text: null})
$remote.select2('data', null)
$remote.select2('data', null)
// clear all option
$('#select_with_blank_data').html('').select2({data: [{id: '', text: ''}]});
// clear and add new option
$("#select_with_data").html('').select2({data: [
{id: '', text: ''},
{id: '1', text: 'Facebook'},
{id: '2', text: 'Youtube'},
{id: '3', text: 'Instagram'},
{id: '4', text: 'Pinterest'}]});
$('#remote').html('').select2({data: {id:null, text: null}});
$('#remote').empty();
success: function(data, textStatus, jqXHR){
$('#remote').change();
}
$("#customers_select").select2("val", "");
.select2('data', null)
.select2('val', null)
$("#remote option").remove();
$('#remote').val(null).trigger("change");
$('#select_id').val('').trigger('change');
for(var i = selectbox.options.length - 1 ; i >= 0 ; i--)
selectbox.remove(i);
$remote.select2.val('');
$remote.select2.html('');
selectedValues = []; // if you have some variable where you store the values
$remote.select2.trigger("change");
$('#mySelect2').val(null).trigger('change');
$('#my_input').select2('destroy').val('').select2();
$remote.empty().append(new Option()).trigger('change');
$('#select2Elem').data('select2').$results.children().remove()