我想根据第一个和第二个下拉列表中的第二个下拉参考值的选择来填充第三个下拉列表。
jQuery
<script type="text/javascript">
$(document).ready(function() {
$("#parent_cat").change(function() {
$.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
$("#sub_cat").html(data);
});
});
$("#sub_cat").change(function() {
$.get('loadsubelement.php?sub_cat=' + $(this).val() + $('#parent_cat').val(), function(data) {
$("#select_subelement").html(data);
});
});
});
</script>
加载子元素.php
<?php
include('config.php');
$parent_cat = $_GET['parent_cat'];
$sub_cat = $_GET['sub_cat'];
$query = mysqli_query($connection, "SELECT * FROM maincategories WHERE categoryID = {$parent_cat}");
$query = mysqli_query($connection, "SELECT * FROM maincategories WHERE subcategoryID = {$sub_cat}");
echo '<option value="">Please select</option>';
while($row = mysqli_fetch_array($query)) {
echo '<option value="'.$row['subcategoryID'].'">' . $row['maincategory_name'] . "</option>";
}
?>