1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <table class="table" width="100%" id="userBox"> <tr class="text-c"> <th ><input type="checkbox" name="allcheck" value="" id="allcheck" onclick="swapCheck(this);"></th> </tr> ...... <tr class="text-c"> <td><input type="checkbox" value="{$v['ul_id']}" id="{$v['ul_id']}" name="userCheck" onclick="swapCheck(this);"></td> ...... </tr> <input id="su_userlist" name="su_userlist" type="hidden"/> </table> <script> var isCheckAll = false; var str = "";; function swapCheck(obj) { var clickId = $(obj).attr("id"); if (isNaN(clickId)) { if (isCheckAll) { $("#userBox input[type='checkbox']").each(function () { this.checked = false; }); isCheckAll = false; } else { $("#userBox input[type='checkbox']").each(function () { this.checked = true; }); isCheckAll = true; } } var chks = $('input[name="userCheck"]');//获取所有用户对象 var result = ""; for (var i = 0; i < chks.length; i++) { if (chks[i].checked) { result += chks[i].id + ","; } } $("#su_userlist").val(result.substring(0, result.length - 1)); } </script> |