Javascript 如何在dropdownbox中附加值
如何使用jquery在dropdownbox中附加值 这是我的htmlJavascript 如何在dropdownbox中附加值,javascript,jquery,ajax,Javascript,Jquery,Ajax,如何使用jquery在dropdownbox中附加值 这是我的html <div class="input-field col s6"> <select id="graph_program" class="Programs"> </select> <label>Program</label> </div> 节目 这是我的剧本 $('#graph_college').on('change',
<div class="input-field col s6">
<select id="graph_program" class="Programs">
</select>
<label>Program</label>
</div>
节目
这是我的剧本
$('#graph_college').on('change',function(){
var college = $('#graph_college option:selected').text();
$.ajax({
type:"POST",
url:"<?php echo base_url('administrator/getCourses')?>",
data:{college:college},
dataType:'json',
success : function(data){
console.log(data);
$(data).each(function(){
$('.Programs').append($('<option class="black-text"></option>').text(this.course_abbv));
});
}
});
});
$('graph#u college')。关于('change',function(){
var college=$('#graph#u college选项:selected')。text();
$.ajax({
类型:“POST”,
url:“”,
数据:{学院:学院},
数据类型:'json',
成功:功能(数据){
控制台日志(数据);
$(数据)。每个(函数(){
$('.Programs').append($('.text)(this.course_abv));
});
}
});
});
结果如下:(项目位于下拉框的底部)
ent$('graph#u college')。关于('change',function(){
var college=$('#graph#u college选项:selected')。text();
$.ajax({
类型:“POST”,
url:“”,
数据:{学院:学院},
数据类型:'json',
成功:功能(数据){
控制台日志(数据);
$(数据)。每个(函数(){
$('.Programs').append($('.text)(this.course_abv));
});
$('select').material_select();//答案
}
});
});
我需要重新初始化materialize的下拉框,您希望这些项目出现在哪里,如果不在底部的话?这是标准行为,如果您需要其他内容,则必须使用自定义下拉元素。我希望它们出现在下拉框中。我对使用jqueryWell很陌生,您的代码很好,请参阅。你看到的是其他原因,我们不可能知道是什么原因,因为它不在你发布的代码中。我使用materialize作为我的cssSo可能就是这个问题。
ent$('#graph_college').on('change',function(){
var college = $('#graph_college option:selected').text();
$.ajax({
type:"POST",
url:"<?php echo base_url('administrator/getCourses')?>",
data:{college:college},
dataType:'json',
success : function(data){
console.log(data);
$(data).each(function(){
$('.Programs').append($('<option class="black-text"></option>').text(this.course_abbv));
});
$('select').material_select(); // answer
}
});
});