我正在尝试使用多维数组在PHP中进行动态下拉列表。
我的第一个选择框正确填充,但是在选择建筑物时,我需要第二个选择框来显示用于第一个选择的相应显示(大厅,休息室等)
这是数组:
$displays = array(
"Company" => array(
"Building 1"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
"Office",
),
),
"Building 2"=>array(
"Displays"=>array(
"Break Room",
"Office",
),
),
"Building 3"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
),
),
"Building 4"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
"Office"
),
),
),
);
到目前为止,我有两个选择框:
/*This select option works to fill the list with building 1 through building 4, as it should*/
<?php foreach($displays["Company"] as $area_name => $area_details): ;?>
/*I need this one to show the displays (lobby, break room, office, etc.) for each builing as it's selected*/
<?php foreach($displays["Company"] as $area_name => $area_details): ;?>
和我不完整的jQuery:
$("#plantSelect").change(function() {
$("#areaSelect").load("/*don't know what to put here*/" + $("#plantSelect").val());
});
非常感谢您完成此工作
参考方案
json_encode数组,并将其作为JS对象存在于页面中
var Company = {
"Building 1": [{
"Displays": [
"Lobby",
"Break Room",
"Office"
]
}],
"Building 2": [{
"Displays": [
"Break Room",
"Office"
]
}],
"Building 3": [{
"Displays": [
"Lobby",
"Break Room"
]
}],
"Building 4": [{
"Displays": [
"Lobby",
"Break Room",
"Office"
]
}]
};
$.each(Company, function(bld) {
$("#plantSelect").append('' + bld + '')
});
$("#plantSelect").on("change", function() {
$("#areaSelect")[0].length=1;
if (this.value) {
$.each(Company[this.value][0].Displays,function(_,disp) {
$("#areaSelect").append('' + disp + '')
});
}
});
Please select
Please select
PHP-复选框组 - php
我有一个需要发布的表单复选框组。
有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:
我想知道如何实现以下项目其实我有一个php代码,可以渲染一张桌子