nbsp; success: function(opt){ $("select[@name=''"+s3+"'']").empty().append(opt);}
});
});
}
};
接下来是PHP里的函数如下========
//城市联动脚本
function cityselect($n=2,$s1=''province'',$s2=''city'',$s3=''area'',$v1=''320000'',$v2=''320500'',$v3=''320501''){
$db = new DB_Sql; //初始化数据库
$db->connect(DB_Database, DB_Host, DB_User, DB_Password); //数据库连接
$db->DB_Sql("set names gbk");
//联动AJAX脚本
$tmp = "<script type=\"text/javascript\"> \n";
$tmp .= ''$(document).ready('';
$tmp .= "function(){ \n";
$tmp .= ''$().cityselect(''.$n.'',\''''.$s1.''\'',\''''.$s2.''\'',\''''.$s3.''\'');'';
$tmp .= "\n";
$tmp .= "});\n";
$tmp .= "</script>\n";
//省份选择
$tmp .= "<select id=\"".$s1."\" name=\"".$s1."\" >\n";
$db->query("select * from sz_chinacity where right(CityPostCode, 4) = ''0000'' order by CityID asc");
while ($db->next_record()){
if ($db->Record[''CityPostCode'']==$v1){
$tmp .= "<option value=\"".$db->Record[''CityPostCode'']."\" selected>".$db->Record[''CityName'']."</option>\n";
}else{
$tmp .= "<option value=\"".$db->Record[''CityPostCode'']."\">".$db->Record[''CityName'']."</option>\n";
}
}
$tmp .= "</select>\n";
//城市选择
$tmp .= "<select id=\"".$s2."\" name=\"".$s2."\">\n";
$cityid = substr($v1,0,2);
$db->query("select * from sz_chinacity where Right(CityPostCode, 2) = ''00'' and Left(CityPostCode, 2)=''".$cityid."'' and Right(CityPostCode, 4) <> ''0000'' order by CityID asc");
while ($db->next_record()){
if ($db->Record[''CityPostCode'']==$v2){
$tmp .= "<option value=\"".$db->Record[''CityPostCode'']."\" selected>".$db->Record[''CityName'']."</option>\n";
}else{
$tmp .= "<option value=\"".$db->Record[''CityPostCode'']."\">".$db->Record[''CityName'']."</option>\n";
}
}
$tmp .= "</select>\n";
if ($n==3){
//地区选择
$tmp .= "<select id=\"".$s3."\" name=\"".$s3."\">\n";
$cityid = substr($v2,0,4);
$db->query("select * from sz_chinacity where Left(CityPostCode, 4)=''".$cityid."'' and Right(CityPostCode, 2) <> ''00'' order by CityID |