我不太清楚你的意思,但根据我的理解,
您有两个下拉选择,
一个作为父选择,第二个是子选择,
子选择下拉值取决于父选择,
你是这个意思吗?
如果是的话,
一个简单的方法是使用jquery和ajax,
您必须阅读基本的 ajax 和事件侦听器才能做到这一点,
第一个选择下拉菜单,
<select id="parent_select">
</select>
<select id="child_select">
</select>
/* 这将填充您的父选择 */
$.ajax({
url: 'url that will display all list'
dataType: 'json',
type: 'get',
success: function(data){
var output = "";
$.each(data, function(a,b){
output += "<option value='"+b.id+"'>"+b.parent_select_name+" </option>"
$("#parent_select").append(output);
});
}
})
/* 这将在更改父母的值时填充您的孩子选择 */
$(document).on("change", "#parent_select", function(){
var parent_id = $(this).attr("id");
$.ajax({
url: 'url that will display child data where parent_id = parent_id ',
type: 'POST',
dataType: 'json',
data: { 'parent_id' : parent_id } /* you are passing parent_id*/
success: function(data){
$("#child_select").empty();
var output = "";
$.each(data, function(a,b){
output += "<option id="+b.child_id+">"+b.child_desc+"</option>";
})
$("#child_select").append(output);
}
})
})