请问,如何在客户端访问CheckBoxList控件?
已经使用了CheckBoxList控件,写了很多代码了,现在,其中一小部功能分出于效率考虑,想移到客户端去做。请问,如果想在客户端,用javascript访问CheckBoxList控件所生成的一系列checkbox中被选中的checkbox的name(或者说label)和value,有办法做到吗?谢谢! 问题点数:100、回复次数:9Top
1 楼clfk(CLFK)回复于 2005-05-11 22:12:37 得分 0
?Top
2 楼guofengx(ttx)回复于 2005-05-11 22:14:11 得分 2
在客户端可以访问。Top
3 楼saucer(思归)回复于 2005-05-11 22:44:10 得分 20
if you have this
<asp:CheckBoxList id="CheckBoxList1" runat="server"/>
on the client side, you are going to have something like
<input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1:0" />
<label for="CheckBoxList1_0">Item 0</label>
<input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1:1" />
<label for="CheckBoxList1_1">Item 1</label>
...
so as you can see, you have to go through form1.elements collection and check the type and the id or name to see if they start with or contain the original CheckBoxList IdTop
4 楼clfk(CLFK)回复于 2005-05-11 23:34:51 得分 0
谢谢saucer(思归),确实如此。那么请问,怎么才能得到“Item 0”、“Item 1”这样的值呢?那是和这个checkbox相关的label,而不直接是checkbox,javascript大致是怎么写的呢?谢谢!Top
5 楼saucer(思归)回复于 2005-05-12 00:00:14 得分 50
assume you get one of the input, in IE,
var input = document.forms[0].elements["CheckBoxList1:0"];
var l = document.all[input.sourceIndex+1];
var s = l.innerText;Top
6 楼clfk(CLFK)回复于 2005-05-12 01:11:22 得分 0
哦,对了!太感谢了!
能不能再请教一下,javascript关于这方面的知识(主要是如何操作各种控件的,比如,您上面用到的sourceIndex,innerText等等),有比较好的学习资料吗?或者好一些的书籍也可以,能不能为我推荐一下?很想比较系统一些学习一下这方面的知识,而一般找到的javascript的教程,以讲解语言本身的居多。非常感谢!Top
7 楼saucer(思归)回复于 2005-05-12 01:24:00 得分 28
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.aspTop
8 楼clfk(CLFK)回复于 2005-05-12 01:38:12 得分 0
哦,呵呵,对呀,把这给忘了,MSDN总是很好的参考手册:)
非常感谢!Top
9 楼tanglingg(唐霖)回复于 2005-06-01 14:26:18 得分 0
你好,我想问如果这个checkboxlist在服务端被数据绑定,应改有Text和Value,你所获取的只是text值,那怎么能获取value值呢?Top




