w框架-结合用户的不同点击路径,提交正确的id集合。
1 <table class="table"> 2 <tr> 3 <td></td> 4 <td>图片</td> 5 </tr> 6 <?php 7 foreach ($wr as $one) { ?> 8 <tr> 9 <td><input class="checkbox_batch_all" name="checkbox_batch_all" type="checkbox" value="<?= $one['id'] ?>" 10 id="<?= $one['autoid'] ?>" 11 onclick="w_mainchoose()"><?= $one['id'] ?></td> 12 <td><img width="100" src="<?= gen_img($link,$one['as']) ?>"></td> 13 </tr> 14 <?php } ?> 15 </table> 16 <button id="wdel" onclick="wdel()">删除所选</button> 17 <button style="display: none;" id="wdel_all" onclick="wdel_all('<?= $id_all ?>')">全部删除</button> 18 <button id="wdel_all_checked" onclick="wdel_all_checked()">全选/全不选</button> 19 20 </form> 21 22 <form id="javascript_form_hidden_batch_delete" action="" method="post"> 23 <input type="hidden" name="javascript_input_batch_delete" id="javascript_input_hidden_batch_delete"> 24 25 <input type="hidden" name="type" value="<?= $wfly ?>"> 26 27 28 </form> 29 <?php include('w_pagination.php'); ?> 30 </body> 31 </html> 32 33 34 <script> 35 36 function getCookie(cname) { 37 var name = cname + "="; 38 var ca = document.cookie.split(';'); 39 for (var i = 0; i < ca.length; i++) { 40 var c = ca[i]; 41 while (c.charAt(0) == ' ') { 42 c = c.substring(1); 43 } 44 if (c.indexOf(name) == 0) { 45 return c.substring(name.length, c.length); 46 } 47 } 48 return ""; 49 } 50 51 var w_form = getCookie('wjs_cookie'); 52 53 54 var warr = new Array(); 55 var warr_distinct = new Array(); 56 var w_all_checked = false; 57 var warr_effect = new Array() 58 59 function w_mainchoose() { 60 wf(this.id) 61 wf(event.target.nodeName) 62 wf(event.target) 63 wf(event.target.getAttribute('id')) 64 // alert(this.getAttribute('id')) 65 var wthis_id = event.target.getAttribute('id') 66 warr = warr_effect 67 warr.push(wthis_id); 68 wf(warr); 69 var tmp = new Array(); 70 tmp = w_arr_copy_value(warr); 71 warr_distinct = w_arr_distinct(tmp); 72 wtip('warr_distinct', warr_distinct); 73 warr_effect = w_arr_odd(warr_distinct, warr) 74 75 } 76 77 78 function w_arr_distinct(arr) { 79 for (var wi = 0; wi < arr.length; wi++) { 80 var tmp = arr[wi]; 81 if (arr.length > 1) { 82 for (var wj = wi + 1; wj < arr.length; wj++) { 83 if (arr[wj] == tmp) { 84 arr.splice(wj, 1); 85 --wj; 86 } 87 } 88 } 89 } 90 return arr; 91 } 92 93 function w_arr_odd(warr_distinct, warr) { 94 var len_warr_distinct = warr_distinct.length; 95 var len_arr = warr.length; 96 var arr_odd = new Array(); 97 for (var wi = 0; wi < len_warr_distinct; wi++) { 98 var tmp = 0; 99 for (var wj = 0; wj < len_arr; wj++) { 100 if (warr_distinct[wi] == warr[wj]) { 101 if (tmp == 0) { 102 tmp = 1; 103 } 104 else if (tmp == 1) { 105 tmp = 0; 106 } 107 } 108 } 109 if (tmp == 1) { 110 arr_odd.push(warr_distinct[wi]); 111 } 112 } 113 return arr_odd; 114 } 115 116 117 function w_arr_copy_value(w_source) { 118 var len = w_source.length; 119 var w_arr = new Array(); 120 var tmp_value = 0; 121 for (var w = 0; w < len; w++) { 122 tmp_value = w_source.slice(w, w + 1); 123 tmp_value = tmp_value + ''; //toString 124 tmp_value = parseInt(tmp_value, 10); //toInt 125 w_arr.unshift(tmp_value); 126 } 127 return w_arr; 128 } 129 130 131 function wdel() { 132 wf('del'); 133 var wvalue = warr_effect.join('w'); 134 wf(wvalue); 135 if (before_submit(wvalue)) { 136 do_submit(wvalue, 'javascript_input_hidden_batch_delete', 'javascript_form_hidden_batch_delete'); 137 } 138 } 139 140 141 function wdel_all_checked() { 142 var w = document.getElementsByName('checkbox_batch_all') 143 wf(w_all_checked) 144 w_all_checked = !w_all_checked; 145 wf(w_all_checked) 146 147 warr_effect.length = 0; 148 for (var wi = 0, len = w.length; wi < len; wi++) { 149 w[wi].checked = w_all_checked; 150 var wid = w[wi].getAttribute('id'); 151 if (w_all_checked == true) { 152 warr_effect.push(wid); 153 } 154 } 155 } 156 157 158 function before_submit(str) { 159 if (str.length == 0) { 160 alert('请勾选删除项!'); 161 return false; 162 } 163 return true; 164 } 165 166 function do_submit(str, input_id, form_id) { 167 var w = show_confirm('您确定要删除吗?'); 168 if (w) { 169 change_input_value(input_id, str); 170 console.log('w123---' + str); 171 document.getElementById(form_id).submit(); 172 } 173 174 } 175 176 function show_confirm(str_tip) { 177 var r = confirm(str_tip); 178 if (r == true) { 179 //alert('pressed ok'); 180 return true; 181 } else { 182 return false; 183 } 184 } 185 186 function wf(w) { 187 console.log(w); 188 } 189 function wtip(tip, w) { 190 console.log(tip); 191 console.log(w); 192 } 193 194 function change_input_value(input_id, value) { 195 wf(value); 196 wf(input_id); 197 document.getElementById(input_id).value = value; 198 } 199 200 </script>