1、默认选中单选框
(1)第一种实现方式:
<select name="level" class="form-control">
<%for(int i=9;i>0;i--){
request.setAttribute("temi", i);
%>
<option value="<%=i%>"<c:if test="${temi==scase.level}">selected="selected"
</c:if>><%=i%></option>
<%} %>
</select>
效果预览:
(2)第二种实现方式:
<select name="level" class="form-control">
<c:forEach var="i" begin="1" end="9">
<option value="${i}"<c:if test="${i==article.level}">selected="selected"</c:if>>
${i}</option>
</c:forEach>
</select>
效果预览:
(3)第三种实现方式:
<select name="price_rmb" class="form-control">
<option value="50 万以下" ${house.price_rmb=="50 万以下"?"selected":""}>50万以下</option>
<option value="50-100万" ${house.price_rmb=="50-100万"?"selected":""}>50-100万</option>
<option value="100万以上" ${house.price_rmb=="200万以上"?"selected":""}>800万以上
</option>
</select>
效果预览:
2、默认选中多选框
<ul class="dowebok">
<li><input type="checkbox" value="住宅" name="types" <%=house.getTypes().indexOf("住宅")!=-1?"checked":"" %> data-labelauty="住宅"></li>
<li><input type="checkbox" value="花园洋房" name="types" <%=house.getTypes().indexOf("花园洋房")!=-1?"checked":"" %> data-labelauty="花园洋房"></li>
<li><input type="checkbox" value="别墅" name="types" <%=house.getTypes().indexOf("别墅")!=-1?"checked":"" %> data-labelauty="别墅"></li>
<li><input type="checkbox" value="公寓" name="types" <%=house.getTypes().indexOf("公寓")!=-1?"checked":"" %> data-labelauty="公寓"></li>
<li><input type="checkbox" value="其它" name="types" <%=house.getTypes().indexOf("其它")!=-1?"checked":"" %> data-labelauty="其它"></li>
</ul>
效果预览: