mvc dropdownlists onchange 怎么用
1个回答
推荐于2016-07-07
展开全部
代码如下:this.DropDownList1.Attributes.Add( "onchange ", "load(this.options[this.selectedIndex].value); ");我在后台添加如上代码,html代码
<script language= "javascript ">
function load(state)
{
var drp2=document.getElementById( "DropDownList2 ");
for(i=drp2.length;i> =0;i--)
{
drp2.options.remove(i);
}
var oHttpReq=new ActiveXObject( "MSXML2.XMLHTTP ");
var oDoc=new ActiveXObject( "MSXML2.DOMDocument ");
oHttpReq.open( "POST ", "getdata.aspx?state= "+state,false);
oHttpReq.send( " ");
result=oHttpReq.responseText;
oDoc.loadXML(result);
items1=oDoc.selectNodes( "//PC1/Table/cId ");
items2=oDoc.selectNodes( "//PC1/Table/cName ");
var itemsLength=items1.length;
for(i=0;i <itemsLength;i++)
{
var newOption=document.createElement( "OPTION ");
newOption.text=items2[i].text;
newOption.value=items2[i].text;
drp2.options.add(newOption);
}
}
window.onload=function()
{
load( '1 ');
}
<script language= "javascript ">
function load(state)
{
var drp2=document.getElementById( "DropDownList2 ");
for(i=drp2.length;i> =0;i--)
{
drp2.options.remove(i);
}
var oHttpReq=new ActiveXObject( "MSXML2.XMLHTTP ");
var oDoc=new ActiveXObject( "MSXML2.DOMDocument ");
oHttpReq.open( "POST ", "getdata.aspx?state= "+state,false);
oHttpReq.send( " ");
result=oHttpReq.responseText;
oDoc.loadXML(result);
items1=oDoc.selectNodes( "//PC1/Table/cId ");
items2=oDoc.selectNodes( "//PC1/Table/cName ");
var itemsLength=items1.length;
for(i=0;i <itemsLength;i++)
{
var newOption=document.createElement( "OPTION ");
newOption.text=items2[i].text;
newOption.value=items2[i].text;
drp2.options.add(newOption);
}
}
window.onload=function()
{
load( '1 ');
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询