单选CheckBoxList

【转个】

最近老大给个页面,要单选CheckBoxList,找了找,没有合适的,还得自己实现

1、在页面上放个CheckBoxList,注意添加了SingleIndex的属性,以及onclick客户端事件

ContractedBlock.gif ExpandedBlockStart.gif Code
 1            <asp:CheckBoxList ID="ckList" runat="server" RepeatLayout="Table" RepeatColumns="3" singleIndex="-1" onclick="singleCheck(this);" >
 2                <asp:ListItem>1</asp:ListItem>
 3                <asp:ListItem>2</asp:ListItem>
 4                <asp:ListItem>3</asp:ListItem>
 5                <asp:ListItem>4</asp:ListItem>
 6                <asp:ListItem>5</asp:ListItem>
 7                <asp:ListItem>6</asp:ListItem>
 8                <asp:ListItem>7</asp:ListItem>
 9                <asp:ListItem>8</asp:ListItem>
10            </asp:CheckBoxList>

 

2、下面我的js脚本

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1<script type="text/javascript">
 2function setSingleIndex(ckTable)
 3ExpandedBlockStart.gifContractedBlock.gif{   
 4    var count=0;
 5    var inputArray=ckTable.getElementsByTagName("input");
 6    for(i=0;i<inputArray.length;i++)
 7ExpandedSubBlockStart.gifContractedSubBlock.gif    {   
 8
 9        if(inputArray[i].checked)
10ExpandedSubBlockStart.gifContractedSubBlock.gif        {
11            ckTable.singleIndex=i;
12            count++;
13        }

14    }

15    if(count==0)
16ExpandedSubBlockStart.gifContractedSubBlock.gif    {
17        ckTable.singleIndex=-1;
18    }

19}

20window.onload=function()
21ExpandedBlockStart.gifContractedBlock.gif{
22    setSingleIndex(document.getElementById("ckList"));
23}

24
25function singleCheck(ckTable)
26ExpandedBlockStart.gifContractedBlock.gif{
27    var index=ckTable.singleIndex;
28    var inputArray=ckTable.getElementsByTagName("input");    
29
30    if(index!=-1)
31ExpandedSubBlockStart.gifContractedSubBlock.gif    {
32        for(i=0;i<inputArray.length;i++)
33ExpandedSubBlockStart.gifContractedSubBlock.gif        {
34            if(inputArray[i].checked&&i==index)
35ExpandedSubBlockStart.gifContractedSubBlock.gif            {
36               inputArray[i].checked=false
37            }

38        }

39    }

40    setSingleIndex(ckTable)
41}

42</script>

 

3、这就是我的实现,比较简单,和大家分享一下,欢迎评论

转载于:https://www.cnblogs.com/eduask0114/archive/2009/03/31/1425905.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值