用JQuery做了个级联菜单,已经成功,但是一提交,或者刷新,级联菜单选择的内容就不回显了,变成初始状态了<script type="text/javascript" src="include/jgxz.js"></script>
<?php
echo "<select id=zh name=zh>";
echo "<option value=''>请选择机构</option>";
echo "</select>";
echo "<select id=wd name=wd></select>";
echo "<input type=submit value=查询>";
?>
//jgxz.js
$(document).ready(
function(){
$.get("./return.php?flag=zh",null,function(data){
$("#zh").append(data);
});
$("#wd").css("display","none");
$("#zh").change(function(){
if($("#zh").val()==""){
$("#wd").css("display","none");
}else{
$.get("./return.php?flag=wd&zh="+$("#zh").val(),null,function(data){
$("#wd").css("display","");
$("#wd").empty();
$("#wd").append("<option value=''>请选择机构</option>");
$("#wd").append(data);
//$("#wd").css("display","none");
});
}
});
}
);//return.php
<?php
header("Content-type:text/html;charset=gbk");
@include("include/oracle.inc2.php");
$handle=ora_logon("$ora_user","$ora_passwd") or die;
$cursor=ora_open($handle);
//获得来自 URL 的 id 参数
$flag=$_GET['flag'];
$str="";
if($flag=='zh'){
$sql="select id,dept2 from deptdata where deptlevel=2";
ora_parse($cursor, $sql) or die;
ora_exec($cursor);
while(ora_fetch_into($cursor,$row,ORA_FETCHINTO_NULLS)) {
$str.="<option value=$row[0]>$row[1]</option>";
}
echo $str;
}
else
{
$sql="select appdeptid,deptname from deptexchg where appsys='999' and up_dept1='$zh'";
ora_parse($cursor, $sql) or die;
ora_exec($cursor);
while(ora_fetch_into($cursor,$row,ORA_FETCHINTO_NULLS)) {
$str.="<option value=".$row[0].">".$row[1]."</option>";
}
echo $str;
}
?>
<?php
echo "<select id=zh name=zh>";
echo "<option value=''>请选择机构</option>";
echo "</select>";
echo "<select id=wd name=wd></select>";
echo "<input type=submit value=查询>";
?>
//jgxz.js
$(document).ready(
function(){
$.get("./return.php?flag=zh",null,function(data){
$("#zh").append(data);
});
$("#wd").css("display","none");
$("#zh").change(function(){
if($("#zh").val()==""){
$("#wd").css("display","none");
}else{
$.get("./return.php?flag=wd&zh="+$("#zh").val(),null,function(data){
$("#wd").css("display","");
$("#wd").empty();
$("#wd").append("<option value=''>请选择机构</option>");
$("#wd").append(data);
//$("#wd").css("display","none");
});
}
});
}
);//return.php
<?php
header("Content-type:text/html;charset=gbk");
@include("include/oracle.inc2.php");
$handle=ora_logon("$ora_user","$ora_passwd") or die;
$cursor=ora_open($handle);
//获得来自 URL 的 id 参数
$flag=$_GET['flag'];
$str="";
if($flag=='zh'){
$sql="select id,dept2 from deptdata where deptlevel=2";
ora_parse($cursor, $sql) or die;
ora_exec($cursor);
while(ora_fetch_into($cursor,$row,ORA_FETCHINTO_NULLS)) {
$str.="<option value=$row[0]>$row[1]</option>";
}
echo $str;
}
else
{
$sql="select appdeptid,deptname from deptexchg where appsys='999' and up_dept1='$zh'";
ora_parse($cursor, $sql) or die;
ora_exec($cursor);
while(ora_fetch_into($cursor,$row,ORA_FETCHINTO_NULLS)) {
$str.="<option value=".$row[0].">".$row[1]."</option>";
}
echo $str;
}
?>
$("#wd").load().....$("#zh").load()....
后台加个
var zh ='<?php echo $_GET["zh"]?>';
var wd='<?php echo $_GET["wd"]?>';
再用这两个值去选select
这个语句不对吧?js和php?