很多事情其实都非常简单,只是你不知道方法而已!
最近学习jQuery下载到的实例源码,自己手写了一遍,算是学习,熟练熟练吧!下次网站里面可能会用到此功能,希望对各位有用,虽然网上很多这样的代码,不过我还记录下!
<html> <head> <script type="text/javascript" src="/jquery/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#selectall").click(function(){ $("[name='shareuser']").each(function(){ $(this).attr("checked",true); }); }); //全选<span id="more-542"></span> $("#fanall").click(function(){ $("[name='shareuser']").each(function(){ if($(this).attr("checked")){ $(this).attr("checked",false); }else{ $(this).attr("checked",true); } }); }); //反选 $("#deselectall").click(function(){ $("[name='shareuser']").each(function(){ $(this).attr("checked",false); }); }); //取消 $("alertall").click(function(){ $("[name='shareuser']").each(function(){ if($(this).attr("checked")){ alert($(this).val()); } }); }); }); </script> </head> <body> <input type='checkbox' id='in-shareuser-10' name='shareuser' value='10' />10 <input type='checkbox' id='in-shareuser-11' name='shareuser' value='11' />11 <input type='checkbox' id='in-shareuser-12' name='shareuser' value='12' />12 <input type="button" id="selectall" name="selectall" value="全选" /> <input type="button" id="fanall" name="fanall" value="反选" /> <input type="button" id="deselectall" name="deselectall" value="取消" /> </body> </html>
提示:你可以先修改部分代码再运行。
姓名 (必填)
Mail (必填,不会被公开)
网站
评论内容