jquery checkbox 全选功能
2015-12-22 17:49
701 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8"></meta> <title></title> <style type="text/css"> table { border-collapse: collapse; } td { border: 1px solid #ccc; } </style> <script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { // chkAll全选事件 $("#chkAll").bind("click", function () { $("[name = chkItem]:checkbox").attr("checked", this.checked); }); // chkItem事件 $("[name = chkItem]:checkbox").bind("click", function () { var $chk = $("[name = chkItem]:checkbox"); $("#chkAll").attr("checked", $("[name = chkItem]:checkbox").length == $("[name = chkItem]:checkbox").filter(":checked").length); }) }); </script> </head> <body> <table id="tb"> <thead> <tr> <td> <input id="chkAll" type="checkbox" /> </td> <td> 分类名称 </td> </tr> </thead> <tbody> <tr> <td> <input name="chkItem" type="checkbox" value="今日话题" /> </td> <td> 今日话题 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="视觉焦点" /> </td> <td> 视觉焦点 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="财经" /> </td> <td> 财经 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="汽车" /> </td> <td> 汽车 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="科技" /> </td> <td> 科技 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="房产" /> </td> <td> 房产 </td> </tr> <tr> <td> <input name="chkItem" type="checkbox" value="旅游" /> </td> <td> 旅游 </td> </tr> </tbody> </table> </body> </html>
相关文章推荐
- JQuery学习笔记
- jQuery学习笔记_DOM操作
- javaScript & jquery完美判断图片是否加载完毕
- jquery Deferred的一点用法
- jQuery UI -- Repeater & 手风琴(Accordion)效果
- jquery速查表
- 通过Ajax发送数据--jQuery方法
- jQuery插件开发,jquery插件
- Jquery实战视频教程学习
- JQuery简单实现图片轮播效果
- 你不需要jQuery
- 你不需要jQuery(二)
- 探索高效jQuery的奥秘
- 'No Transport' Error w/ jQuery ajax call in IE
- 你不需要jQuery(三):新AJAX方法fetch()
- jquery1.9 下检测浏览器类型和版本的方法
- 你不需要jQuery(四)
- jquery serialize序列化中文乱码问题
- JQuery textarea中val(),text()
- jQuery Ajax 实例 ($.ajax、$.post、$.get)