嘿伙计们,我很难用动态创建的值选项来触发我的下拉列表。
<label>Year Level Advisory: </label>
<select id="org-subject-advisory-level" name="subject_level">
</select>
<label>Subjects: </label>
<select id="subjects-list">
</select>
jQuery ajax:
function get_my_advisory(){
$.ajax({
url:'func_students.php',
type:'POST',
dataType:'json',
data:{'func_num':'4'},
success: function (data){
$.each(data, function(i, item) {
var options = "<option value="+data[i].sec_level+">"+data[i].sec_level+"</option>";
$('#org-subject-advisory-level').append(options);
});
}
});
}
get_my_advisory();
$('#org-subject-advisory-level').on("change", function(){
var advisory_year_level = $('#org-subject-advisory-level').val();
alert(advisory_year_level);
$('#subjects-list').html("");
$.ajax({
type:'POST',
url:'add_subject.php',
dataType:'json',
data:{'func_numbr':'9','year_level':advisory_year_level},
success:function (data){
$.each(data, function(i, item) {
html = "<option value="+data[i].subj_id+">"+data[i].subj_name+"</option>";
$('#subjects-list').append(html);
});
}
});
});
$('#org-subject-advisory-level').trigger("change");
触发器有效,但它在警报时返回空值,我想知道为什么会这样。希望得到你们的帮助。我是 jquery 和 php 的新手。提前致谢