我正在尝试清除jQuery选定的下拉列表并刷新它。
HTML:
<select data-placeholder="Select Picture..." class="chosen-select" style="width:250px;" id="picturegallery" tabindex="2">
<option value="" selected="selected"></option>
<option value="x">remove me</option>
</select>
当我点击“刷新”按钮时,它应该变成这样:
<select data-placeholder="Select Picture..." class="chosen-select" style="width:250px;" id="picturegallery" tabindex="2">
<option value="1">test</option>
</select>
我尝试过的:
$("#refreshgallery").click(function(){
$('#picturegallery').empty();
var newOption = $('<option value="1">test</option>');
$('#picturegallery').append(newOption);
});
但我不能让它更新下拉列表...有帮助吗?:)
发布于 2018-07-05 17:27:05
如果trigger("chosen:updated");
不工作,使用@Nhan Tran的.trigger("liszt:updated");
它工作正常。
发布于 2017-07-21 14:59:02
$("#idofBtn").click(function(){
$('#idofdropdown').empty(); //remove all child nodes
var newOption = $('<option value="1">test</option>');
$('#idofdropdown').append(newOption);
$('#idofdropdown').trigger("chosen:updated");
});
发布于 2014-12-21 00:23:28
MVC 4:
function Cargar_BS(bs) {
$.getJSON('@Url.Action("GetBienServicio", "MonitoreoAdministracion")',
{
id: bs
},
function (d) {
$("#txtIdItem").empty().append('<option value="">-Seleccione-</option>');
$.each(d, function (idx, item) {
jQuery("<option/>").text(item.C_DescBs).attr("value", item.C_CodBs).appendTo("#txtIdItem");
})
$('#txtIdItem').trigger("chosen:updated");
});
}
https://stackoverflow.com/questions/20148195
复制相似问题