jquery ajax 三级联动菜单问题

2025-02-26 13:56:24
推荐回答(2个)
回答1:

php文件:
$sql="select * from tb_category where first!=''";
$result=$db->Execute($sql);
$firstcat=$db->GetArray($sql);
$smarty->assign("firstcat",$firstcat);
js文件

$(function(){
$("#arttype").change(function(){
var catid=$(this).val();
$.ajax({
type:"POST",
url:"second.php",
data:"catid="+catid,
success:function(ss)
{
$("#er").html(ss);
}
})
/*if($(this).val()==0)
{
$("#er").css("display","none");
}
else{
$("#er").css("display","block");
}*/
})
$("#second").change(function(){
var catid=$(this).val();
$.ajax({
type:"POST",
url:"third.php",
data:"catid="+catid,
success:function(rr){
$("#san").html(rr);
}
})
})
})

html文件:






er.tpl文件:

也要引用js文件
san.tpl文件:
引用js文件
third.php文件

include_once("smarty.php");
include_once("../conn.php");
$catid=$_POST['catid'];
$sql="select * from tb_category where parentid=".$catid;
$result=$db->Execute($sql);
$third=$db->GetArray($sql);
$smarty->assign("third",$third);
$smarty->display("san.tpl");

second.php文件:
header("Content-Type:text/html; charset=gb2312");
include_once("smarty.php");
include_once("../conn.php");
$catid=$_POST['catid'];
$sql="select * from tb_category where parentid='".$catid."'";
$result=$db->Execute($sql);
$second=$db->GetArray($sql);
$smarty->assign("second",$second);
$smarty->display("er.tpl");

回答2:

那可能是空间问题。