ajax无刷新省市区三级联动菜单

来源:互联网  作者:本站整理
摘要:1、GetCity.aspx?pid=private void Page_Load(object sender, System.EventArgs e)// 在此处放置用户代码以初始化页面Regex re=new Regex("^[0-9]……

4、主页面

Page_Load:
this.ddlProvince.Attributes.Add("onchange","return g('c');");
this.ddlCity.Attributes.Add("onchange","return g('z');");
this.ddlZone.Attributes.Add("onchange","return z();");
javascript:

<script lang="javascript">
function p(t)
{
document.all("ctl_loaded_h"+t).value=document.all("ctl_loaded_ddl"+t).value;

//alert(document.all("ctl_loaded_h"+t).value);
if(document.all("ctl_loaded_ddl"+t).selectedIndex!=0)
{
document.all("img"+t).style.display="inline";
document.all("img"+t).src="/ShowImage.aspx?id="+document.all("ctl_loaded_ddl"+t).value;
}
else
{
document.all("img"+t).style.display="none";
document.all("img"+t).src="";
}
if(t=='Position')
{
document.all("ctl_loaded_ddlFrame").focus();
}
else if(t=='Frame')
{
 document.all("ctl_loaded_ddlPic1").focus();
}
if(t=='Pic1')
{
 document.all("ctl_loaded_ddlPic2").focus();
}
if(t=='Pic2')
{
 document.all("ctl_loaded_ddlPic3").focus();
}
if(t=='Pic3')
{
 document.all("ctl_loaded_ddlPic4").focus();
}
if(t=='Pic4')
{
 document.all("ctl_loaded_ddlPic5").focus();
}
if(t=='Pic5')
{
 document.all("ctl_loaded_btnFB").focus();
}
}
</script>
<script language="javascript">
var req = false;
function g(t)
{
req = false;
if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
req = new XMLHttpRequest();
if (req.overrideMimeType)
{
req.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{ // IE      
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{alert(e);return false;}
}
}
if (!req)
{     
return false;
}
if(t=='c')
{
document.all("ctl_loaded_zone").value='0';
document.all("ctl_loaded_city").value='0';
document.all("ctl_loaded_province").value=document.Form1.ctl_loaded_ddlProvince.selectedIndex;
for(i=document.all("ctl_loaded_ddlCity").options.length-1;i>0;i--)
{
document.all("ctl_loaded_ddlCity").options.remove(i);
}      
for(i=document.all("ctl_loaded_ddlZone").options.length-1;i>0;i--)
{
document.all("ctl_loaded_ddlZone").options.remove(i);
}

if(document.Form1.ctl_loaded_ddlProvince.selectedIndex==0)
{                      
return false;      
}
else
{
req.open('GET', '/GetCity.aspx?pid='+document.Form1.ctl_loaded_ddlProvince.selectedIndex, true);
req.onreadystatechange = onC;
document.all("ctl_loaded_ddlCity").focus();
}
}
else if(t=='z')
{
document.all("ctl_loaded_zone").value=0;
document.all("ctl_loaded_city").value=document.Form1.ctl_loaded_ddlCity.selectedIndex;
for(i=document.all("ctl_loaded_ddlZone").options.length-1;i>0;i--)
{
document.all("ctl_loaded_ddlZone").options.remove(i);
}
if(document.Form1.ctl_loaded_ddlCity.selectedIndex==0)
{                              
return false;      
}
else
{
req.open('GET', '/GetZone.aspx?pid='+document.Form1.ctl_loaded_ddlProvince.selectedIndex
+'&cid='+document.Form1.ctl_loaded_ddlCity.selectedIndex, true);
req.onreadystatechange = onZ;
document.all("ctl_loaded_ddlZone").focus();
}
}
else if(t=='i')
{
for(i=document.all("ctl_loaded_ddlPosition").options.length-1;i>0;i--)
{
document.all("ctl_loaded_ddlPosition").options.remove(i);
document.all("ctl_loaded_ddlFrame").options.remove(i);
document.all("ctl_loaded_ddlPic1").options.remove(i);
document.all("ctl_loaded_ddlPic2").options.remove(i);
document.all("ctl_loaded_ddlPic3").options.remove(i);
document.all("ctl_loaded_ddlPic4").options.remove(i);
document.all("ctl_loaded_ddlPic5").options.remove(i);
}
req.open('GET', '/GetImages.aspx?uid='+<%=Session["xxptw_cor_user_name"]%>, true);
req.onreadystatechange = onI;
}
else
{
return false;
}
//http_request.open('GET', '/GetCity.aspx?pid=1', true);
req.send(null);
}

【相关文章】好搜一下
小方法大作用:如何让网站PR值一路高歌

小方法大作用:如何让网站PR值一路高歌

做网站最痛苦的就是建站之初的那段时间,如长沙厂房出租网站刚建立,只是处于婴幼儿时…