<script type="text/javascript"> function selectDefaultOption(selectId,value) { if (value == null || "" == value) { return; } var selectObj = document.getElementById(selectId); if (selectObj == null) { return; } selectObj.value = value; } </script>
上面的JS在上面body前或者外部放在JS
<select name="education" id="education" style="width:155px" > <c:set value="0" var="education_flag"/> <c:choose> <c:when test="${!empty educationList}"> <c:forEach items="${educationList}" var="choiceParamBean"> <c:choose> <c:if test="${(consumerInfoBean.education == '')||(consumerInfoBean.education eq null)}"> <c:if test="${education_flag eq 0}"> <option value=""selected="selected">请选择</option> </c:if> <c:set value="1" var="education_flag"/> </c:if> <c:if test="${choiceParamBean.cp_value !=''}"> <option value="${choiceParamBean.cp_value }">${choiceParamBean.cp_value }</option> </c:if> </c:choose> </c:forEach> </c:when> <c:otherwise> <option value="">请添加相关信息</option> </c:otherwise> </c:choose> </select> <script type="text/javascript"> selectDefaultOption("education","${consumerInfoBean.education}"); </script>
selectDefaultOption("education","${consumerInfoBean.education}");
这个函数的参数的解释是.
eduction是select的id, "${consumerInfoBean.education}" 是默认值.
应该说是对应的.