
// 獲取勾選的標簽值得上一個兄弟節點
var groups = [];
$('input[name="group_name"]:checked').siblings(".lable").each(function(){
groups.push($(this).contents()); });
// 將Groups的長度賦值給隱藏域
$("#groupsCount").val(groups.length);
<c:forEach items="${lableGroupList}" var="var" varStatus="vs">
<div>
<label class="lable"
style="line-height: 30px;margin:0 15px;">
${var.group_name}:</label>
<c:forEach items="${lableList}" var="lable" varStatus="vs">
<c:choose>
<c:when
test="${lable.itemcat_group_id == var.itemcat_group_id}">
<input name="group_name"
value="${lable.itemcat_id}" type="checkbox" />
${lable.itemcat_name}
</c:when>
</c:choose>
</c:forEach>
</div>
</c:forEach>
<input type="hidden" id="groupsCount" name="groupsCount">
$('#id').siblings(" 指定兄弟節點的id") 當前元素所有的兄弟節點
$('#id').prev(" 指定兄弟節點的id") 當前元素前一個兄弟節點
$('#id').prevaAll(" 指定兄弟節點的id") 當前元素之前所有的兄弟節點
$('#id').next(" 指定兄弟節點的id") 當前元素之后第一個兄弟節點
$('#id').nextAll(" 指定兄弟節點的id") 當前元素之后所有的兄弟節點