全选 全不选 反选
<button onclick="aa1()">全选</button><button onclick="bb1()">取消全选</button><button onclick="xx1()">反选</button><br /> <input type="checkbox" name="" id="" value="" />春节<br /> <input type="checkbox" name="" id="" value="" />五一<br /> <input type="checkbox" name="" id="" value="" />国庆<br /> <input type="checkbox" name="" id="" value="" />元旦<br />
function aa1(){ var qx= document.getElementsByTagName("input"); for(i = 0;i < 4; i++){ qx[i].setAttribute("checked","checked"); } } function bb1(){ var qbx= document.getElementsByTagName("input"); for(i= 0 ;i < 4; i++){ qbx[i].removeAttribute("checked"); } } function xx1(){ var fx =document.getElementsByTagName("input"); for(var i=0;i<4;i++){ if(fx[i].checked){ fx[i].checked=false; }else{ fx[i].checked = true; } } }
效果图: