jquery全选反选

来源:互联网 发布:淘宝吧 编辑:程序博客网 时间:2024/05/20 11:32
 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0px auto; padding: 0px; } .d{ width: 500px;     }   </style> <script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script> <script> $(function (){ $("#qbt").click(function (){ $("[name='p']").each(function (){ $(this).prop("checked",true) })   }) $("#bt").click(function (){ $("[name='p']").each(function (){ $(this).prop("checked",false) }) }) $("#fbt").click(function (){ $("[name='p']").each(function(){ $(this).prop("checked",!$(this).prop("checked")) }) })   })     </script> </head> <body> <div class="d"> 游戏<input type="checkbox" name="p" /> YY<input type="checkbox" name="p" /> QQ<input type="checkbox" name="p" /> 看奥特曼<input type="checkbox" name="p" /><br /><br /> <input type="button" id="qbt" value="全选" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" id="bt" value="不选" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" id="fbt" value="反选" /> </div>   </body> </html> 
原创粉丝点击