如果您想要一个更动态的解决方案(可以容纳对后台数据库的更改),则可以在页面上执行以下操作:
<script> function changeSecond(first){ var xmlhttp; if (window.XMLHttpRequest) {// pre for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// pre for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var res=xmlhttp.responseText; document.getElementById("second").innerHTML=res; } } xmlhttp.open("GET","second_script.php?first="+first,true); xmlhttp.send(); } </script>...<select onChange="changeSecond(this.value)"><option value="Degree">Degree</option><option value="City">City</option></select><div id="second"><select><option value=""></option></select></div>然后是一个类似于以下内容的脚本:
<?php//database connection$first=mysql_real_escape_string($_REQUEST["first"]);$query="SELECT ".$first." FROM tablename GROUP BY ".$first;$data=mysql_query($query);echo "<select>";while($row=mysql_fetch_row($data)){echo "<option value="".$row[0]."">".$row[0]."</option>";}echo "</select>";?>我想为了获得真正的灵活性,您还想在上面类似的另一个脚本中使用mysql_field_name动态填充第一个



