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

来源:互联网 发布:剑三成男绯梨数据 编辑:程序博客网 时间:2024/05/16 09:06

例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>

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

0 0