我在GridView中有一行模版列放了CheckBox我想点击一个Button时,用JS判断是否选中一个checkbox,没有就提示~~

解决方案 »

  1.   

    你把那个checkbox设个id,然后在生成后的html里面找这个id!暂时没有想到其他的办法!
      

  2.   

    function chkAll_true()
    {
    var chkall= document.all["chkAll"];
    var chkother= document.getElementsByTagName("input");//找模版中CheckBox
    for (var i=0;i<chkother.length;i++)
    {
    if( chkother[i].type=='checkbox')
    {
    if(chkother[i].id.indexOf('chkExport')>-1)
    {
    if(chkall.checked==true)
    {
    chkother[i].checked=true;
    }
    else
    {
    chkother[i].checked=false;
    }
    }
    }
    }
    }
      

  3.   

    楼上的是判断全选吧~我的意思是~如果我一个都没选就点击按扭的话就alert("你没选中任何节点")
      

  4.   

    function Check()
    {
       var flag = false;
       var chk;
       chk=document.forms[0].elements;
       for(var i=1 ;i<chk.length ;i++)
       {
         if(chk[i].checked)
         {
              flag = true;  
          }
        }
        if(!flag)
           window.alert("你没选中任何节点");
    }
      

  5.   

    其中i值自己根据实际需要调整,例如如果你有全选这个checkbox而不喜欢判断它,可以把i设成2
      

  6.   

    楼上好象没判断var chk的类型是什么,而且如果在gridView外也有checkbox怎么办?我只想判断GridView里面的~有没有只获取gridview里的元素在做判断
      

  7.   

    给checkbox加name属性,然后用getElementsByName
      

  8.   

    我这样写~电脑提示报错说我少一个括号
    <script language=javascript type="text/javascript">
                function chkAll_true()
    {
        var t = document.getElementById("<%=GridView1.ClientID%>");
                    var b=false;
                  for(i=1;i<rows.length;i++)
    {
    if((t.rows[i].findcontrol("checkbox1") as checkbox).checked))//说这里少了括号     {
                     b=true
                   }
      
            }
                    if(b==false)
                    {
                       alert("您没选中任何节点");
                    }

    }
    </script>