繁体   English   中英

从JSP scriptlet变量检查单选按钮

[英]checked radio button from JSP scriptlet variable

这将是一个愚蠢的问题,但我需要提出这个问题。 PS:这是一种古老的做法,但我需要这种方式。 在scriptlet中,我的status可变。

 <%
   String status=bean.getStatus();
   //Status value is coming from database which is either "1" or "0"(String type)
 %>

在表单中,我有单选按钮。

<tr>
<td> Status :</td>
<td>Active
            <input type="radio" name="status" checked="checked" id="statusAct" value="1" />
    Inactive
           <input type="radio" name="status" id="statusInac" value="0"/>
</tr>

如果status==1我想和单选按钮id="statusAct"被选择,并且如果status==0 ,然后用无线电id="statusInac"被选择。

我可以使用javascript或jQuery,但不知道如何将Java变量放入javascript函数中。

你可以简单地做

<input type="radio" name="status" <% ${bean.getStatus() == '1' ? 'checked="checked"' : '' } %> id="statusAct" value="1" />

<input type="radio" name="status" <% ${bean.getStatus() == '0' ? 'checked="checked"' : '' } %> id="statusInac" value="1" />

可以使用scriptlet进行条件逻辑,然后在需要的地方写出checked =“ checked”。 在脚本中,您可以执行操作。 println写入页面(输出流)。 您还可以将jstl用于条件标签c:if

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM