jQuery全选反选插件
2017-11-28 10:35
316 查看
(function($){ $.fn.check = function(options){ var options = $.extend({ element : "input[name='node']" },options); return this.each(function(){ var self = $(this); var elements = $(options.element); self.click(function(){ elements.each(function(index,dom){ dom.checked = self.prop("checked"); //将本身self的状态赋值给elements的状态 }); }); elements.click(function(){ var leng = elements.filter(":checked").length; if(leng == elements.length){ self.prop("checked",true); }else{ self.prop("checked",false); } }); }); } })(jQuery);
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <table> <thead> <tr> <th><input type="checkbox" id="selAll"/>全选</th> </tr> </thead> <tbody> <tr> <td>1.<input type="checkbox" name="node"/></td> </tr> <tr> <td>2.<input type="checkbox" name="node"/></td> </tr> <tr> <td>3.<input type="checkbox" name="node"/></td> </tr> <tr> <td>4.<input type="checkbox" name="node"/></td> </tr> </tbody> </table> <script src="../jquery.min.js"></script> <script src="check.js"></script> <script> $("#selAll").check(); </script> </body> </html>
自写了一个全选反选的jQuery插件,根据项目需求进行插件的修改,如根据选择的数量来进行是否选中。
相关文章推荐
- jQuery插件如何编写02_ 简单的全选插件
- 一个简单的全选Jquery插件
- 自制jQuery 复选框全选与反选插件
- checkbox 全选/反选功能的 jquery插件(支持多页保持选择)
- jQuery表格插件(隔行换色、划过变色、全选)
- jquery插件开发(checkbox全选的简单实例)
- jQuery插件如何编写05_ 简单的全选反选插件(完整版)
- JQuery全选与取消插件
- jquery的全选插件
- jquery全选插件制作
- jQuery插件如何编写03_ 简单的全选反选插件
- jquery checkbox 选中 全选 插件
- bootstrap-datepicker时间插件和chosen.jquery下拉模糊搜索和bootbox.min弹出框以及jquery.tips提示框和js的全选与取消的使用
- 一个简单的全选Jquery插件
- jQuery 插件 表格高亮显示选中行 全选、反选(四种模式)
- jquery插件-checkbox全选插件
- 基于jQuery的简单全选插件
- jQuery表格插件(隔行换色、划过变色、全选)
- jQuery插件如何编写04_ 简单的全选反选插件(关联了主复选框和子复选框,代码简单)
- jQuery--简单的全选反选插件