select标签以及默认选中当前分类问题

例1:

                <select id="select" style="height:28px" name="categoryId">
                    <c:forEach items="${categorys}" var="category">
                            <c:if test="${blog.categoryId==category.id}">
                        <option value="${category.id }" selected>${category.name }</option>  
                            </c:if>
                            <c:if test="${!(blog.categoryId==category.id)}">
                         <option value="${category.id }" >${category.name }</option>  
                            </c:if>
                    </c:forEach>
                </select>

备注:例如 传到前台blog和categorys
其中blog有所属分类的id,所有分类都有id。两者相等时,显出当前分类

例2:性别下拉
默认数据库中 1是男,0时女;

<select style="width:100px;">
        <c:if test="${user.gender==1}">
                <option value="1"></option>>
        </c:if>
        <c:if test="${!(user.gender==1)}">
                <option value="0"></option>
        </c:if>
</select>

此处注意下拉框的样式修改

猜你喜欢

转载自blog.csdn.net/root_zhb/article/details/70249496