<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="jquery.min.js"></script> </head> <body> <form id='myForm' name="myForm" method="post" action="test6.php">
<input type="checkbox" id='all' >:全部</input>
<input type="checkbox" class="list" name='list[]' value="1" >:1</input>
<input type="checkbox" class="list" name='list[]' value="2" >:2</input>
<input type="checkbox" class="list" name='list[]' value="3" >:3</input>
<br/> <br/> <select name="select"> <option>1</option> <option>2</option> <option>3</option> </select> <input type="button" id="but" value="sub"></input> <input type="submit" id="but" value="sub12"></input> </form> </body> </html> <script type="text/javascript"> $(document).ready(function($) { $("#all").click(function(event) { if($('#all').prop('checked')){ $('.list').prop('checked',true); }else{ $('.list').prop('checked',false); } }); $(".list").click(function(event) { var arr_stu = []; $('.list').each(function(index, el) { var statu = $(this).prop('checked'); arr_stu.push(statu); }); $.unique(arr_stu).length==1?$('#all').prop('checked',true):$('#all').prop('checked',false); }); $('#but').click(function(){ var data = $('#myForm').serialize(); $.ajax({ url: 'test6.php', type: 'post', dataType: 'json', data: data, success:function(result){ } }) }) }); </script>