/** * @version 1.0 * @author:like * @Date: 2011/07/07 16:37:07 */ ;(function($) { $.fn.extend({ /**全选 *call:$(调用对象).allSelect({bySelectID:"被调用对象"}); */ "allSelect":function(options){ //设置默认值 options=$.extend({ bySelectID:"bySelectID", /* 被选择checkbox ID*/ selected:"selectedid" /* 选中行样式*/ },options); var byID=options.bySelectID; $(this).click(function(){ var hasSelected=$(this).attr('checked'); if(hasSelected){ $("input[id='"+byID+"']").attr('checked',true); }else{ $("input[id='"+byID+"']").attr('checked',false); } }); }, /**获取所有选择项的值 *call:$(调用对象).allSelectVal(); *return:调用对象选中的val值 */ "allSelectVal":function(){ var selectIDs=""; $(this).each(function(){ var hasSelected=$(this).attr('checked'); if(hasSelected){ selectIDs+=$(this).val()+","; } }); return selectIDs; } }); })(jQuery);
//全选按钮绑定事件 $("#admin_member_select").allSelect({bySelectID:"admin_memberID"}); 注:admin_member_select 选择框ID admin_memberID 被选择框ID