4

我需要根据请求中存在的值将单选按钮设置为选中状态。下面是我在我的 JSP 中使用的代码

<input type="radio" name="status" id="status" value="Active" checked="<c:if test="${posting.postingStatus eq 'Active'}">checked</c:if>">
                Active&nbsp; 
<input type="radio" name="status" id="status" value="Closed" checked="<c:if test="${posting.postingStatus eq 'Closed'}">checked</c:if>">
                Closed

我得到单选按钮以及文本'checked/>Active'和另一个单选按钮,文本'checked/>Closed'

我尝试使用另一组代码

<c:choose>
    <c:when test="${posting.postingStatus eq 'Active'}">
    <input type="radio" name="status" id="status" value="Active" checked="checked"/>
    Active&nbsp; 
    <input type="radio" name="status" id="status" value="Closed"/>
    Closed
    </c:when>
    <c:otherwise>
    <input type="radio" name="status" id="status" value="Active" />
    Active&nbsp;
    <input type="radio" name="status" id="status" value="Closed" checked="checked"/>
    Closed
    </c:otherwise>

我得到了两倍的结果,结果不正确。

谁能帮我这个?

4

1 回答 1

16

试试这个方法:

    <input type="radio" name="status" id="status"
     value="Active" ${posting.postingStatus=='Active'?'checked':''}>
于 2013-10-08T12:24:45.513 回答