<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>全选,反选,全不选</title> <head></head> <script type="text/javascript" src="jquery-1.4.3.js"></script> <script type="text/javascript"> $(function(){ $("#CheckedAll").click(function(){ $("#playList :checkbox").attr("checked",true); }); $("#unSelect").click(function(){ $("#playList :checkbox").attr("checked",false); }); $("#reverse").click(function(){ $("#playList :checkbox").each(function(){ $(this).attr("checked",!$(this).attr("checked")); }) }); $("#send").click(function(){ var str = "你选中的爱好: "; $('input[type=checkbox][name=items]:checked').each(function(){ str+=$(this).val()+' '; }); alert(str); }); }); </script> <body> <form> 你爱好的运动是?<br/><input type="button" id="CheckedAll" value="全选"/><br/> <input type="button" id="unSelect" value="全不选"/><br/> <input type="button" id="reverse" value="反选"/><br/> <div id="playList"> <input type="checkbox" name="items" value="足球"/>足球 <input type="checkbox" name="items" value="篮球"/>篮球 <input type="checkbox" name="items" value="羽毛球"/>羽毛球 <input type="checkbox" name="items" value="乒乓球"/>乒乓球<br/> <input type="button" id="send" value="提 交"/> </div> </form> </body> </html>