日期:2014-05-18  浏览次数:20546 次

asp.net 级联菜单
ajax+asp.net
已经通过ajax取得返回的数组,如何添加到DropDownList中?

var   DropDownList1=document.getElementById( 'DropDownList1 ');
xmlhttp.open( 'get ', 'inc/getzlflone.aspx ');
xmlhttp.onreadystatechange=function(){

下面该如何去写?
数组格式:[ '项目管理 ',1, '程序实现 ',2, '实战经验 ',3,0]

1,直接写入   硬值填充!
2,缓存一下!

------解决方案--------------------
以前写的一个连动
function getData()
{try {
xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP ");
} catch (e) {
try {
xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP ");
} catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined ') {
xmlhttp = new XMLHttpRequest();
}
//获取用户填写的名称
var d=document.getElementById( "DropDownList1 ");
var city=d.options[d.selectedIndex].text;

//创建异步调用对象
// xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP ");
//将对象状态与事件相关联
xmlhttp.onreadystatechange=statechange;
//加载要链接的页面
xmlhttp.Open( "POST ", "datapage.aspx?city= " +city,true);
//发送请求
xmlhttp.Send();
}
function statechange()
{
//判断异步调用是否已经完成
if(xmlhttp.readystate==4)
{
//判断完成的提示代码是否是OK状态
if(xmlhttp.status==200)
{
//将返回数据作为参数,传递给填充方法
FillData(xmlhttp.responseText);


}
}
}
function FillData(strcity)
{


var indexofcity;
var city;
var select= " ";


//切割传递来的字符串
while(strcity.length> 0)
{
//判断是否是最后一个字符串
indexofcity=strcity.indexOf( ", ");
if(indexofcity > 0)
{
city=strcity.substring(0,indexofcity);
strcity=strcity.substring(indexofcity+1);
//填充下拉框

select+= " <option> "+city+ " </option> ";

}
else
{
// 如果是最后一个字符串


select+= " <option> "+strcity+ " </option> </select> ";

var result= " <select id= 'didid ' name= 'dff ' style= 'width:157px;height:20px;border:1px solid #B1B1B1;font-size:12px; '> "+select;

document.getElementById( "divdropdownlist ").innerHTML=result;

break;
}
}
}
------解决方案--------------------


var HouseMembers = response.value;

for (var i = 0; i < HouseMembers.Rows.length; ++i)
{
HouseMemberList.options[HouseMemberList.options.length] = new Option(HouseMembers.Rows[i].House_Name, HouseMembers.Rows[i].House_ID);
}



------解决方案--------------------
var droplist = document.getElementById( "你的ID ");
droplist.length = 0;
var arr = Array( "1 ", "2 ");

for(var i = 0;i <arr.length;i++)
{
var option = document.createElement( "