html代码
<input type="hidden" name="f_information_id" id="f_information_id" value="<?php echo $f_information_id?>"> <table class="table table-hover"><thead><tr><th> <input type="checkbox" class="btn btn-xs btn-primary btn-outline " id="check_all"> 全选 </input></th><th>姓名</th><th>差评</th></tr></thead><tbody><?php if (count($comments_record)) {foreach ($comments_record as $one) { ?><tr class="gradeC"><td><input type="checkbox" class="btn btn-sm btn-primary choose_admin" id="<?php echo $one['f_admin_id'];?>" value="<?php echo $one['f_admin_id']?>" name="choose_admin" data-can-choose="true"/></td><td><?php echo $admin_record[$one['f_admin_id']]['f_name']; ?></td><td><?php echo $one['f_num'];?></td></tr><?php }} ?></tbody> </table>
js代码
//全选var flag = true; // 未选中$("#check_all").click(function(){if(flag) {var chk_value = [];$('input[name="choose_admin"]').each(function(){$(this).attr("checked",true);chk_value.push($(this).val());var admin_ids = chk_value.join(","); //js中数组转换为字符串$("#admin_ids").val(admin_ids); //把选中的复选框赋值给hidden的input中 });}else {$('input[name="choose_admin"]').each(function(){$(this).removeAttr("checked");$("#admin_ids").val(); //把选中的复选框赋值给hidden的input中 });}flag = !flag;});$(".choose_admin").change(function () {var chk_value = [];$('input[name="choose_admin"]:checked').each(function(){chk_value.push($(this).val());});var admin_ids = chk_value.join(","); //js中数组转换为字符串 $("#admin_ids").val(admin_ids); //把下载的选项赋值给hidden的input中});