近日在做一个小网站,需要实现DropDownList与CheckBoxList的无刷新联动,网上有很多关于两个及以上DropDownList联动的例子!但还没有看到DropDownList与CheckBoxList的无刷新联动的例子,我按照DropDownList联动的例子改写DropDownList与CheckBoxList的无刷新联动,但一直有问题!
<script language= "javascript " type= "text/jscript ">
function load(MC_ID)
{
var drp2 = document.getElementById( "CheckBoxList1 ");
function RemoveAll(oElem)
{
var i = 0;
for (i = oElem.length; i > = 0; i--)
{
oElem.options.remove(i);
}
}
RemoveAll(drp2)
var oHttpReq = new ActiveXObject( "MSXML2.XMLHTTP ");
var oDoc = new ActiveXObject( "Microsoft.XMLDOM ");
oHttpReq.open( "POST ", "DropChild.aspx?ClassID= "+MC_ID, false);
oHttpReq.send( " ");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items1 = oDoc.selectNodes( "//Table/MC_Name ");
items2 = oDoc.selectNodes( "//Table/MC_ID ");
var itemsLength=items1.length;
alert(itemsLength);
for(i=0;i <itemsLength;i++)
{
var newOption = document.createElement( "Items ");
newOption.text=items1[i].text;
newOption.value=items2[i].text;
alert(newOption.text); //调试到此处时一切正常,可正常得到值
drp2.options.add(newOption);
}
}
</script>
一直报 "options为空或不是对象 "的错~,查看页面源代码后发现CheckBoxList 呈现到客户端之后,是一个个的 inpu type=checkbox ,无options 属性,不知道怎样解决!,望各位高手指点迷津!谢谢
<script language= "javascript " type= "text/jscript ">
function load(MC_ID)
{
var drp2 = document.getElementById( "CheckBoxList1 ");
function RemoveAll(oElem)
{
var i = 0;
for (i = oElem.length; i > = 0; i--)
{
oElem.options.remove(i);
}
}
RemoveAll(drp2)
var oHttpReq = new ActiveXObject( "MSXML2.XMLHTTP ");
var oDoc = new ActiveXObject( "Microsoft.XMLDOM ");
oHttpReq.open( "POST ", "DropChild.aspx?ClassID= "+MC_ID, false);
oHttpReq.send( " ");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items1 = oDoc.selectNodes( "//Table/MC_Name ");
items2 = oDoc.selectNodes( "//Table/MC_ID ");
var itemsLength=items1.length;
alert(itemsLength);
for(i=0;i <itemsLength;i++)
{
var newOption = document.createElement( "Items ");
newOption.text=items1[i].text;
newOption.value=items2[i].text;
alert(newOption.text); //调试到此处时一切正常,可正常得到值
drp2.options.add(newOption);
}
}
</script>
一直报 "options为空或不是对象 "的错~,查看页面源代码后发现CheckBoxList 呈现到客户端之后,是一个个的 inpu type=checkbox ,无options 属性,不知道怎样解决!,望各位高手指点迷津!谢谢