JQuery选择:正确使用trigger("liszt:updated")
JQuery Chosen: Using trigger("liszt:updated") Correctly
我有两个不同的 selection 用于城市和地区。当用户更改城市 selection 我更新地区 selection.
有我的代码:
$("#city").change(function () {
$.ajax({
url: '<?php echo SITE_URL; ?>/process/getDistricts?city=' + $(this).val(),
type: 'get',
success: function (data) {
data = JSON.parse(data);
var districts = $("#district");
districts.empty();
districts.append('<option value=""> İlçe Seçiniz </option>');
for (var i = 0; i < data.length; i++) {
districts.append('<option value="' + data[i].ID + '">' + data[i].name + '</option>');
}
$("#district").trigger("liszt:updated");
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
如果我不添加 districts.append('<option value=""> İlçe Seçiniz </option>');
行,第一个分区选项会自动 select。
然后我的 "search-choice-close" 按钮就这样消失了:
如何正确更新我的 liszt selection?
从选择documentation:
Note: on single selects, the first element is assumed to be selected
by the browser. To take advantage of the default text support, you
will need to include a blank option as the first element of your
select list.
这意味着您需要添加一个空白元素作为默认文本的占位符。
此外,我在您的代码或图像中看不到 "search-choice-close"。
我有两个不同的 selection 用于城市和地区。当用户更改城市 selection 我更新地区 selection.
有我的代码:
$("#city").change(function () {
$.ajax({
url: '<?php echo SITE_URL; ?>/process/getDistricts?city=' + $(this).val(),
type: 'get',
success: function (data) {
data = JSON.parse(data);
var districts = $("#district");
districts.empty();
districts.append('<option value=""> İlçe Seçiniz </option>');
for (var i = 0; i < data.length; i++) {
districts.append('<option value="' + data[i].ID + '">' + data[i].name + '</option>');
}
$("#district").trigger("liszt:updated");
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
如果我不添加 districts.append('<option value=""> İlçe Seçiniz </option>');
行,第一个分区选项会自动 select。
然后我的 "search-choice-close" 按钮就这样消失了:
如何正确更新我的 liszt selection?
从选择documentation:
Note: on single selects, the first element is assumed to be selected by the browser. To take advantage of the default text support, you will need to include a blank option as the first element of your select list.
这意味着您需要添加一个空白元素作为默认文本的占位符。
此外,我在您的代码或图像中看不到 "search-choice-close"。