用JavaScript获取Asp.net服务器端控件

2013 年 9 月 1 日5490

【IT168技术文档】

Asp.net服务器端控件CheckBoxList在客户端没有生成value值,所以就想在客户端通过JS获得选中项就很麻烦了。
迫于无奈,只能写了以下的代码。比较通用,适合于CheckBoxList的属性RepeatLayout为Flow和Table,属性RepeatDirection为Horizontal和Vertical
objID为服务器端控件在客户端生成的ID

通用版本(不依赖任何类库)





function GetCheckBoxListValue(objID)



{



Array();



document.getElementById(objID);



)



{



)



)



])



)



v.push(CheckBoxList.rows[i].cells[j].childNodes[1].innerText);



}



)



{



)



)



)



{



i++;



v.push(CheckBoxList.childNodes[i].innerText);



}



}



return v;



}



Asp.net Ajax版本(依赖Asp.net Ajax类库支持)



function GetCheckBoxListValue(objID)



{



Array();



$get(objID);



)



{



)



)



])



)



Array.add(v,CheckBoxList.rows[i].cells[j].childNodes[1].innerText);



}



)



{



)



)



)



{



i++;



Array.add(v,CheckBoxList.childNodes[i].innerText);



}



}



return v;



}



0 0