Php nested selectbox-更改第一个jquery下拉列表时设置第二个jquery下拉列表
我正在尝试使用jQuery/AJAX和PHP/MySQL创建一组动态下拉框。当页面基于数据库中的值加载时,将填充第一个下拉框。第二个下拉框应根据第一个下拉框中的选择显示一组值 我使用选择的插件,以便有搜索选项 我的问题是:当我选择第一个选择框时,第二个选择框中没有显示任何内容。当我从Html中删除class=selected时,它工作正常 我需要在选择框中进行搜索。那么,我该怎么办Php nested selectbox-更改第一个jquery下拉列表时设置第二个jquery下拉列表,php,jquery,ajax,drop-down-menu,jquery-chosen,Php,Jquery,Ajax,Drop Down Menu,Jquery Chosen,我正在尝试使用jQuery/AJAX和PHP/MySQL创建一组动态下拉框。当页面基于数据库中的值加载时,将填充第一个下拉框。第二个下拉框应根据第一个下拉框中的选择显示一组值 我使用选择的插件,以便有搜索选项 我的问题是:当我选择第一个选择框时,第二个选择框中没有显示任何内容。当我从Html中删除class=selected时,它工作正常 我需要在选择框中进行搜索。那么,我该怎么办 <script type="text/javascript" charset="utf-8"> $(d
<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>
提前谢谢。最后,我找到了答案:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('.chosen-select').chosen({
no_results_text: "Oops, nothing found!"
});
$('select#search1').on('change', function (){
$('select#search2').html("<option value=''>Select the Option..</option>");// add this on each call then add the options when data receives from the request
$.getJSON('select.php', {id: $(this).val()}, function(data){
$('select#search2').empty();
var options = '<option value="0">Select the Option..</option>';
for (var x = 0; x < data.length; x++) {
options += '<option value="' + data[x]['id'] + '">' + data[x]['Date'] + '</option>';
}
$('select#search2').chosen();
$('select#search2').html(options);
$("#search2").trigger("chosen:updated");
});
});
});
</script>