日期:2014-05-17  浏览次数:20827 次

<c:if>标签,单选按钮选中的问题。
HTML code
<c:if test="${team.sex=='男'}">
                            <input type="radio" id="sex" value="男" name="team.sex" checked="checked"/> 男&nbsp;&nbsp;&nbsp; 
                            <input type="radio" id="sex1" value="女" name="team.sex" /> 女 
                            </c:if>
                            <c:if test="${team.sex=='女'}">
                            <input type="radio" id="sex" value="男" name="team.sex"/> 男&nbsp;&nbsp;&nbsp; 
                            <input type="radio" id="sex1" value="女" name="team.sex" checked="checked"/> 女 
                            </c:if>



我这是一个编辑页面,
想要的是,如果从数据库里面查询的值是男,则编辑页面性别那块选中 男,
如果是女,则编辑页面显示女

但是我这样写之后,页面一个都没有选中呢,
这是为什么呢~

------解决方案--------------------
Java code

<input type="radio" id="sex" value="男" name="team.sex" <%=request.getAttribute("team.sex") != null && request.getAttribute("team.sex").toString().equals("男")?"checked":""%>/> 男&nbsp;&nbsp;&nbsp; 
        <input type="radio" id="sex1" value="女" name="team.sex" <%=request.getAttribute("team.sex") != null && request.getAttribute("team.sex").toString().equals("女")?"checked":""%> /> 女

------解决方案--------------------
LZ 怎么还在纠结哦 都说了在el里面 == 是和后台比较是一个意思,比较内存地址不是表面值,要比较表面值是用 eq 这个来比较 快去试试吧