本帖最后由 a124699279 于 2014-05-20 14:53:07 编辑

解决方案 »

  1.   

    function dan()
       {
         var a = document.getElementsByName("danxuan");
      for(i=0;i<a.length;i++)
         {
            if(a[i].type!="checkbox")
            {
               document.getElementByName("duoxuan").checked=false;
            }

         }
     
       }
      

  2.   

    <script>
    window.onload=function()
    {
    var oBtn=document.getElementById('btn');
    oBtn.onclick=function(){
    if(detechIsAllChecked('group_name'))
    alert('全部选中');
    else
    alert('不是全部选中');
    }
    }
    function detechIsAllChecked(name)
    {
    var aEles=document.getElementsByName(name);
    for(var i=0;i<aEles.length;i++)
    {
    if(!aEles[i].checked)
    return false;
    }
    return true;
    }
    </script>
    </head><body>
    <p>
    <input type="checkbox" value="0" name="group_name" id="group_name_1"><label for="group_name_1">选项1</label>
    <input type="checkbox" value="1" name="group_name" id="group_name_2"><label for="group_name_2">选项2</label>
    <input type="checkbox" value="2" name="group_name" id="group_name_3"><label for="group_name_3">选项3</label>
    <input type="checkbox" value="3" name="group_name" id="group_name_4"><label for="group_name_4">选项4</label>
    </p>
    <input type="button" id="btn" value="检测"/>
    </body>
      

  3.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Insert title here</title>
    <script>
    function  selectRadio(a)
    {//alert(a==1);
    if(a==1)
    loopCheckbox(true);
    if(a==2)
    loopCheckbox(false);

    }
    //循环复选框
    function loopCheckbox(param)
    {//alert(param==true);
    var checkboxs = document.getElementsByName("checkbox");
    for(var i=0;i<checkboxs.length;i++)
    {
    if(param == true){
    checkboxs[i].checked = true;}
    else
    checkboxs[i].checked = false;
    }
    }
    //判断复选框
    function checkCheckbox()
    {
    var checkboxs = document.getElementsByName("checkbox");
    for(var i=0;i<checkboxs.length;i++)
    {
    if(checkboxs[i].checked == false)
    return false;
    }
    return true;
    }
    function selectCheckbox()
    {
    var radios = document.getElementsByName("radio");
    for(var i=0;i<radios.length;i++)
    {
    if(checkCheckbox())
    {
    if(radios[i].value == "全选")
    radios[i].checked = true;
    }else
    {
    if(radios[i].value == "不全选")
    radios[i].checked = true;
    }
    }
    }
    </script>
    </head>
    <body>
    <input type="radio" name="radio" onclick="selectRadio(1)" value="全选"/>全选<br/>
    <input type="radio" name="radio" onclick="selectRadio(2)" value="不全选" />不全选<br/><input type="checkbox" name="checkbox" onclick="selectCheckbox()">1
    <input type="checkbox" name="checkbox" onclick="selectCheckbox()">2</body>
    </html>