当前位置:首页>网络学院>程序开发>ASP.NET教程>文章内容

JavaScript实现DropDownList(Select)三级联动无刷新

[ 来源:www.it55.com | 作者: | 时间:2007-07-15 | 收藏 | 推荐 ] 【

Javascript代码

IT资讯之家 www.it55.com

<script language=javascript>
function CountryChange(){
countryid=document.getElementById("ddlContry").value;
if(countryid==null||countryid==""){
alert("请选择所属国家");
CountryDel("ddlProvince");//清空DropDownList
CountryDel("ddlCity");//清空DropDownList
return false;
}
var countrystring="";
var posturl=location.protocol+"//"+location.hostname+"//soleweb//AjaxEnjine//AreaShow.aspx?AreaId="+countryid;
countrystring=openUrl(posturl);
if(countrystring=="-2"){//查询失败
alert("数据查询失败");
return false;
}
//分割并写入DropDownList

CountryDel("ddlProvince");//清空DropDownList
CountryDel("ddlCity");//清空DropDownList
if(countrystring==""){
return false;
}

var stringarray=countrystring.split("|"); sflj www.it55.com kg^&fgd
for(var i=0;i<stringarray.length;i++){//重写DropDownList
//拆分内部数组
var optionarray=stringarray[i].split(",");
var newoption=document.createElement("option");
newoption.text=optionarray[0];
newoption.value=optionarray[1];
document.getElementById("ddlProvince").options.add(newoption);  
}
}

function CountryDel(AreaName){//清空DropDownList
var countnum=document.getElementById(AreaName).options.length;
for(var i=1;i<countnum;i++){//清空DropDownList
document.getElementById(AreaName).remove(countnum-i);
}
}

function ProvinceChange(){
countryid=document.getElementById("ddlProvince").value;
if(countryid==null||countryid==""){
alert("请选择所属省");
CountryDel("ddlCity");//清空DropDownList
return false;
}

vd;k;l www.it55.com rdfg

var countrystring="";
var posturl=location.protocol+"//"+location.hostname+"//soleweb//AjaxEnjine//AreaShow.aspx?AreaId="+countryid;
countrystring=openUrl(posturl);
if(countrystring=="-2"){//查询失败
alert("数据查询失败");
return false;
}
//分割并写入DropDownList

CountryDel("ddlCity");//清空DropDownList
if(countrystring==""){
return false;
}

var stringarray=countrystring.split("|");
for(var i=0;i<stringarray.length;i++){//重写DropDownList
//拆分内部数组
var optionarray=stringarray[i].split(",");
var newoption=document.createElement("option");
newoption.text=optionarray[0];
newoption.value=optionarray[1];
document.getElementById("ddlCity").options.add(newoption);  
}
}

function openUrl(url)

http://www.it55.com/


{
var objxml=new ActiveXObject("Microsoft.XMLHttp")
objxml.open("GET",url,false);
objxml.send();
retInfo=objxml.responseText;
if (objxml.status=="200")
{
return retInfo;
}
else
  {
return "-2";
}
}
</script>

sflj www.it55.com kg^&fgd

Html代码 it55.com

<asp:DropDownList ID="ddlContry" runat="server" onchange="CountryChange()" OnSelectedIndexChanged="ddlContry_SelectedIndexChanged">
<asp:ListItem Value=" ">请选择所属国家</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlProvince" runat="server" onchange="ProvinceChange()" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">
<asp:ListItem Value=" ">请选择所属省</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server">
<asp:ListItem Value=" ">请选择所属市</asp:ListItem>
</asp:DropDownList>
IT资讯之家 www.it55.com

Aspx.cs代码

sflj www.it55.com kg^&fgd

protected void Page_Load(object sender, EventArgs e)
{
SoLe.Common.StringFormat sft = new SoLe.Common.StringFormat();
string AreaId = sft.Html_Fn(Request.QueryString["AreaId"].ToString());
StringBuilder AreaString = new StringBuilder();
AreaString.Append("");
if (!Page.IsPostBack)
{
//Response.Write(AreaIdValid(AreaId.ToString()));
SoLe.BLL.AreaTable bll = new SoLe.BLL.AreaTable();

(编辑:IT资讯之家 www.it55.com

返回顶部
共2页: 上一页 1 [2] 下一页  

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]

图片文章