我需要根据另一个组合的值隐藏或显示组合,找到下面的代码:
<TR>
<TD>
<span >Nazione</span><br>
<select name="residence_nation" class="form_textfield" id="residence_nation" style="width: 300px;">
<c:forEach var="iNation" items="${iListNation}" varStatus="rowCounter" >
<c:choose>
<c:when test="${iNation.id==iUserInfo.residence_nation}">
<option value="${iNation.id}" selected="selected">
<c:out value="${iNation.name}" />
</option>
</c:when>
<c:otherwise>
<option value="${iNation.id}" >
<c:out value="${iNation.name}" />
</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</TD>
<TD>
<c:choose>
<c:when
test="${residence_nation.???==106}">
<span >Provincia</span><br>
<select name="residence_province" class="form_textfield" id="residence_province" style="width: 150px;">
<c:forEach var="iProvince" items="${iListProvince}" varStatus="rowCounter" >
<c:choose>
<c:when test="${iProvince.id==iUserInfo.residence_province}">
<option value="${iProvince.id}">
<c:out value="${iProvince.name}"/>
</option>
</c:when>
<c:otherwise>
<option selected="selected" value="${iProvince.id}">
<c:out value="${iProvince.name}" />
</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</c:when>
<c:otherwise>
<span>Provincia</span><br>
<input name="residence_province" type="text" class="form_textfield" id="residence_province_input" size="55" value="
<c:out value="${iUserInfo.residence_province_ext}" />
" >
</c:otherwise>
</c:choose>
</TD>
</TR>
我不知道如何使用JSTL来使用residence_nation选项值。
<c:when test="${residence_nation.???==106}">
找到我的JavaScript
$("#residence_nation").change(function()
{
if ($(this).val()!=106)
{
$('#residence_province').hide();
$('#residence_city').hide();
$('#residence_province_input').show();
}else
{
$('#residence_province').show();
$('#residence_city').show();
$('#residence_province_input').hide();
}
});
有谁知道我该怎么做?
答案 0 :(得分:0)
你真的不能那样做:JSTL和表达式语言在服务器端评估,而不是客户端。如果客户端在其浏览器中更改了residence_nation
选择表单输入元素,则JSP页面中的表达式语言无法进行更改。
为此您需要使用Javascript:jQuery通常是我的首选库。有关使用select
元素的一百万个jQuery教程:规范的一个是here。当residence_nation
字段的值发生变化时,您可以绑定隐藏/显示正确选项的函数。
答案 1 :(得分:0)
大家好我以这种方式解决了这个问题:
<c:forEach var="iNation" items="${iListNation}" varStatus="rowCounter" >
<c:choose>
<c:when test="${iNation.id==iUserInfo.residence_nation}">
<option value="${iNation.id}" selected="selected"><c:out value="${iNation.name}" /></option>
<c:set var="iStrNation" value="${iNation.name}" />
</c:when>
<c:otherwise>
<option value="${iNation.id}" ><c:out value="${iNation.name}" /></option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
<TD>
<span >Provincia</span><br>
<c:set var="iStrItalia" value="Italia" />
<c:choose>
<c:when test="${iStrNation==iStrItalia}">
<c:set var="iStyleProvInput" value="display: none;" />
<c:set var="iStyleProvSelect" value="" />
</c:when>
<c:otherwise>
<c:set var="iStyleProvInput" value="" />
<c:set var="iStyleProvSelect" value="display: none;" />
</c:otherwise>
</c:choose>
<input name="residence_province" type="text" class="form_textfield" style ="${iStyleProvInput}" id="residence_province_input" size="55" value="<c:out value="${iUserInfo.residence_province_ext}" />" >
<select name="residence_province" style ="${iStyleProvSelect}" class="form_textfield" id="residence_province" style="width: 150px;">
<c:forEach var="iProvince" items="${iListProvince}" varStatus="rowCounter" >
<c:choose>
<c:when test="${iProvince.id==iUserInfo.residence_province}">
<option value="${iProvince.id}"><c:out value="${iProvince.name}"/></option>
</c:when>
<c:otherwise>
<option selected="selected" value="${iProvince.id}"><c:out value="${iProvince.name}" /> </option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
</TD>