我一直在关注这个解决方案1来创建一个下拉列表,根据用户先前在页面较高的另一个下拉列表中的选择进行更改。但是,我不确定我需要在 Options 中做什么,最初会在这里填充
谢谢
<?php
mysql_connect('localhost');
mysql_select_db("test");
$result = mysql_query("SELECT * FROM `contents` WHERE `parent` = 0");
echo "<select name='name'>";
while(($data = mysql_fetch_array($result)) !== false)
echo '<option value="', $data['id'],'">', $data['name'],'</option>'
?>
<select onchange="ajaxfunction(this.value)">
<!-- Options would have been initially populated here -->
</select>
<select id="sub">
</select>
<script type="text/javascript"> function ajaxfunction(parent)
{
$.ajax({
url: 'process.php?parent=' + parent;
success: function(data) {
$('#sub option').remove(); //// here sub is the id of second select box
$('#sub').append(data)
}
});
}
</script>