checkbox全选实例

来源:互联网 发布:建材网发布软件 编辑:程序博客网 时间:2024/05/17 08:39
                                      <c:if test="${!empty mobiles }">        <tr>        <td colspan="1" class="field" style="width:70px;" >移动<input type="checkbox" id="mobileall"/>:</td>        <td colspan="3">           <c:forEach items="${mobiles}" var="mobile">              <input type="checkbox" name="productId" value="${mobile.id }" class="mobilepid"/>             <span>移动${mobile.packageSize}M</span>               </c:forEach>        </td>        </tr>    </c:if>



$(function(){$("#mobileall").click(function (){$(".mobilepid").prop("checked",this.checked);getDatapackageIds();});$(".mobilepid").click(function() {    var $subs = $(".mobilepid");    $("#mobileall").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);    getDatapackageIds();});});function getDatapackageIds(){/* var $productId = $("input[name='productId']:checked"); var productIds ="";if($productId.length > 0){for(var i = 0; i < $productId.length;i++){alert($productId[i]);alert($productId[i].val());//productIds += $productId[i].val();}}alert(productIds);  */var datapackageIds ="";$("input[name='productId']:checked").each(function(){datapackageIds += $(this).val()+",";});$("#productLimit").val(datapackageIds); }


0 0
原创粉丝点击