小编Kal*_*ran的帖子

基于条件的单选按钮自动检查使用jstl

我需要根据请求中的值将单选按钮设置为已选中.下面是我在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
Run Code Online (Sandbox Code Playgroud)

我正在获取radiobutton以及文本'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>
Run Code Online (Sandbox Code Playgroud)

我得到了两次不正确的结果.

谁能帮我这个?

jstl

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

jstl ×1