项目场景:
jeecg框架,界面需要隐藏控件,其中有一个label是循环获取数据(<c:foreach 省略代码>)后在界面显示。
问题描述:
给<c:foreach 省略代码>下label添加id后设置$(’#id’).hide();只能隐藏循环的第一个数据,其余数据仍然在界面中显示
<c:forEach items="${request.EntityList}" var="Entity" >
<span onchange="setValue();"><label id="type"
for="${Entity.type}">${Entity.typename}</label><input type="checkbox"
id="${Entity.typecode}"
name="name"
value="${Entity.typecode}"/> </span>
</c:forEach>
原因分析:
forEach循环多条数据,但id只能获取一个label控件,应该使用name
解决方案:
将label id="type"改为label name=“type”。
<c:forEach items="${request.EntityList}" var="Entity" >
<span onchange="setValue();"><label name="type"
for="${Entity.type}">${Entity.typename}</label><input type="checkbox"
id="${Entity.typecode}"
name="name"
value="${Entity.typecode}"/> </span>
</c:forEach>
然后设置隐藏:
$("label[name='type']").hide();