您需要为每个下拉选项使用 ajax,并将特定表的返回 json 对象存储到 javascript 对象
<select name="selector1" id="selector1" onChange="getoptions();"
<option value="1">--Select--</option>
<option value="2">option1</option>
<option value="3">option2</option>
<option value="4">option3</option>
</select>
<select name="selector2" id="selector2">
</select>
<select name="selector3" id="selector3">
</select>
下拉菜单的javascript代码就像
function getoptions(){
$('#selector2').html('<option value="">--Select--</option>');
$('#selector3').html('<option value="">--Select--</option>');
var selector1 = $('#selector1').val();
jQuery.get('getdropAjax.php', {'_action_':'GetDropValue', Selector1val : selector1 }, function(r) {
for (var i in r.forselector2)
{
$('#selector2').append('<option value="'+i+'">'+r.forselector2[i]+'</option>');
}
for (var i in r.forselector3)
{
$('#selector3').append('<option value="'+i+'">'+r.forselector3[i]+'</option>');
}
}, 'json');
}
你的 php 代码就像
<?php
$data = array();
switch ( $_GET['_action_'] ){
case 'GetDropValue':
$arr1 = array();
$rs = mysql_query("SELECT `colname` FROM sn_roles");
while($obj = mysql_fetch_object($rs)) {
$arr1[] = $obj->colname;
}
$data['forselector2'] = $arr1;
$arr2 = array();
$rs = mysql_query("SELECT `colname` FROM table2");
while($obj = mysql_fetch_object($rs)) {
$arr2[] = $obj->colname;
}
$data['forselector2'] = $arr2;
return json_encode($data);
?>