js实现全选checkbox

js代码

function selectAllCheckBox(parentid) {
            var PID = document.getElementById(parentid);
            var cb = PID.getElementsByTagName("input");
            for(var i=0;i<cb.length;i++){
                if(cb[i].type == "checkbox"){
                    cb[i].checked = "checked";
                }
            }
        }

表单

<div id = "awardall-frame-down">
  <button id = "selectallbtn" class="selectallbtn" onclick="selectAllCheckBox('awardall-frame-down')">全选</button>
  <input type="checkbox" name="area_id" value="Car">一区</input>
  <input type="checkbox" name="area_id" value="Car">二区</input>
  <input type="checkbox" name="area_id" value="Car">三区</input>
  <input type="checkbox" name="area_id" value="Car">四区</input>
  <input type="checkbox" name="area_id" value="Car">五区</input>
  <input type="checkbox" name="area_id" value="Car">六区</input>
  <input type="checkbox" name="area_id" value="Car">七区</input>
  <input type="checkbox" name="area_id" value="Car">八区</input>
</div>

 

posted @ 2016-08-26 11:00  巫谢  阅读(475)  评论(0编辑  收藏  举报