【发布时间】:2014-11-25 00:29:34
【问题描述】:
我正在尝试使用 jQuery/AJAX 和 PHP/MySQL 创建一组动态的下拉框。当页面根据数据库中的值加载时,将填充第一个下拉框。第二个下拉框应根据第一个下拉框中的选择显示一组值。
我使用 Chosen 插件来获得搜索选项。
我的问题是:当我选择第一个选择框时,第二个选择框没有显示任何内容。当我从 Html 中删除 class="chosen-select" 时,它可以正常工作!
我需要在选择框中进行搜索。那么,我该怎么办?
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('.chosen-select').chosen({
no_results_text: "Oops, nothing found!"
});
$('#search1').on('change', function (){
$('#search2').html("<option value=''>Select</option>");// add this on each call then add the options when data receives from the request
$.getJSON('select.php', {id: $(this).val()}, function(data){
var options = '';
for (var x = 0; x < data.length; x++) {
options += '<option value="' + data[x]['id'] + '">' + data[x]['Date'] + '</option>';
}
$('#search2').html(options);
//$('.chosen-select').chosen();
});
});
});
</script>
这是第二次选择:
<select id="search2" name="search" type="text" data-placeholder="Choose an Option..." style="width:370px;" class="chosen-select" onChange="drawChart(this.value);">
<option value=""></option>
</select>
在此先感谢您。
【问题讨论】:
标签: php jquery ajax drop-down-menu jquery-chosen