在DataList中放<asp:CheckBox.....
运行后是:
<form name="SltDay" method="post">
<input name="dltoday:_ctl0:chk" id="dltoday__ctl0_chk" type="checkbox" onclick="clearOfCheckBox(this);" value="105" checked="checked" />
AAAAAA
<input name="dltoday:_ctl1:chk" id="dltoday__ctl1_chk" type="checkbox" onclick="clearOfCheckBox(this);" value="111" />
BBBBBB
<input name="dltoday:_ctl2:chk" id="dltoday__ctl2_chk" type="checkbox" onclick="clearOfCheckBox(this);" value="112" />
ccccc
</form>function clearOfCheckBox(obj)
{
    for(var i=0;i<document.SltDay.elements.length;i++)
{
var e = document.SltDay.elements[i];
if ((e.type=='checkbox')&&(obj!=e))
{
e.checked = false;
}
}
}每次只能选一个Checkbox,但上面的js是错的,请帮忙,谢谢。

解决方案 »

  1.   

    http://search.csdn.net/Expert/topic/2283/2283584.xml?temp=5.166262E-02
      

  2.   

    那你用radiobutton不就行了吗。
      

  3.   

    <HTML>
    <HEAD>
    <title>ViewList</title>
    <script language="JavaScript" type="text/JavaScript">function setCheck(thischeck)
    {
    var a = document.getElementsByName("ck");
    for(i=0; i<a.length; i++)
    {
    a[i].checked=false;
    }
    thischeck.checked=true;
    }</script></HEAD>
    <body>
    <form id="form1" method="post" >    <input name="ck" type="checkbox" id="ck" onclick="setCheck(this)" value="checkbox" /> 
      First  
        <input name="ck" type="checkbox" id="ck" onclick="setCheck(this)" value="checkbox" /> 
      Second 
        <input name="ck" type="checkbox" id="ck" onclick="setCheck(this)" value="checkbox" /> 
      Third
        
    </form>
    </body>
    </HTML>