动态checkbox 问题
我现在做的一个东西需要在做更新的时候把从数据库取出的checkbox选中。
从数据库取出的是一个cIndustrys.(当前行业)
页面中把所有的checkbox都列出(行业)。如果条件相同就checked="checked"
问题:当所把所有的行业都列出,(所有行业 industrys)行业 父类 和子类,当前行业是包括父子类的。
怎么选中:
代码如下:但会输出两次
从数据库取出的是一个cIndustrys.(当前行业)
页面中把所有的checkbox都列出(行业)。如果条件相同就checked="checked"
问题:当所把所有的行业都列出,(所有行业 industrys)行业 父类 和子类,当前行业是包括父子类的。
怎么选中:
代码如下:但会输出两次
<c:forEach items="${cIndustrys}" var="cIndustry">
<c:set value="false" var="isEmpty"></c:set>
<c:set value="false" var="isEmpty2"></c:set>
<c:forEach items="${industrys}" var="industry">
<c:choose>
<c:when test="${cIndustry.industryId==industry.industryId}">
<input type="checkbox" class="check" checked="checked" name="industry" value="${industry.industryId}">${industry.industryCnName}</br>
</c:when>
<c:otherwise>
<input type="checkbox" class="check" name="industry" value="${industry.industryId}">${industry.industryCnName}</br>
</c:otherwise>
</c:choose>
<c:forEach items="${industry.subIndustries}" var="sub">
<c:choose>
<c:when test="${cIndustry.industryId==sub.industryId}">
<input type="checkbox" class="check" checked="checked" name="industry" value="${sub.industryId}">${sub.industryCnName}</br>
</c:when>
<c:otherwise>
<input type="checkbox" class="check" name="industry" value="${sub.industryId}">${sub.industryCnName}</br>
</c:otherwise>
</c:choose>
</c:forEach>
</c:forEach>
</c:forEach>
...全文
相关推荐
Vue动态生成el-checkbox点击无法赋值的解决方法
特别是当涉及到动态生成的表单元素,比如checkbox(复选框)时,开发者可能会遇到点击复选框无法正确赋值的情况。本文将详细阐述出现这一问题的原因以及如何解决。
对layui初始化列表的CheckBox属性详解
在使用layui框架构建前端页面时,经常会遇到动态加载数据的问题,特别是涉及到列表的初始化和CheckBox属性的使用。
layui 动态设置checbox 选中状态的例子
这篇内容将通过实例讲解如何在layui框架下动态设置checkbox的选中状态,并指出在动态添加和修改界面元素时可能遇到的问题及其解决方法。首先,我们来理解一下动态设置checkbox选中状态的含义。
动态获取recyclerView中CheckBox的值
- **CheckBox状态同步**:确保CheckBox的状态在用户交互过程中正确更新,避免状态不同步的问题。
jQuery 更改checkbox的状态,无效的解决方法
在开发网页时,可能会遇到使用jQuery操作复选框checkbox状态的问题。当你试图动态地使所有复选框全选或全不选时,可能发现使用`$.attr()`方法在某些情况下会出现问题,尤其是当首次点击后,


Web 开发
