基於js實現checkbox批量選中操作_javascript技巧

來源:互聯網
上載者:User

本文執行個體為大家分享了js實現checkbox批量選中的具體代碼,供大家參考,具體內容如下

<html > <head> <title>checkbox全選</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"></style> <script type="text/javascript"></script> </head> <body> <table style="border:1px solid red;">    <tr>  <th style="background-color:#f7f7f7;width:8%;text-align:center;" class="lf">  <input name='chkAll' type='checkbox' id='chkAll' onClick="checkAll(this, 'id[]')" value='checkbox' /> 全選  </th>  <th style="background-color:#f7f7f7;width:8%;" class="lf">商品編號</th>  <th style="background-color:#f7f7f7;width:13%;" class="lf">名稱</th>  <th style="background-color:#f7f7f7;width:18%;" class="lf">標題</th>   <th style="background-color:#f7f7f7;width:8%;" class="lf">品牌</th>  <th style="background-color:#f7f7f7;width:8%;" class="lf">組別</th>   </tr>  <tr>  <td class="lf" style="text-align:center;">  <input name='id[]' type='checkbox' value='{id}' onClick="checkItem(this, 'chkAll')">  </td>  <td class="lf">001</td>  <td class="lf">002</td>  <td class="lf">003</td>  <td class="lf">004</td>  <td class="lf">005</td>   </tr>   <tr>  <td class="lf" style="text-align:center;">  <input name='id[]' type='checkbox' value='{id}' onClick="checkItem(this, 'chkAll')">  </td>  <td class="lf">001</td>  <td class="lf">002</td>  <td class="lf">003</td>  <td class="lf">004</td>  <td class="lf">005</td>   </tr>   <tr height="45">  <td colspan="10" style="text-align:left;padding-left:40px;">  <input type="button" id="btn_show" value="批量展示" style="width:100px;margin-left:20px;">  </td>   </tr> </table><script type="text/javascript" src="jquery-1.7.1.min.js"></script><script type="text/javascript" src="checkbox.js"></script><script type="text/javascript"> /*var ids = []; $('#btn_show').click(function(){ btnCheck('展示'); data = { "ids":ids }; $.ajax({ type:"POST", url:"{:U('Mall/GoodsShow')}", data:data, //dataType:"json", success:function(msg){ if(msg == 00){  alert("批量展示成功");  window.location.href='/index.php/Admin/Mall/MallList'; }else{  alert("批量展示失敗,請重新編輯"); } }, error:function(){  alert("大量編輯失敗,請重新編輯"); } });   }); function btnCheck(info){ var obj = $("input[name='id[]']:checked").each(function(){ ids.push($(this).val()); }); if (ids == false) { alert("請選定要"+info+"的商品"); return false; }else { return ids;  } }*/</script> </body></html>

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.