jSP的3种方式实现radio ,checkBox,select的默认选择值。
2014-04-11 11:30
633 查看
jSP的3种方式实现radio ,checkBox,select的默认选择值。
以radiao 为例:
第一种方式:在jsp中使用java 脚本,这个方法最直接,不过脚本太多,不容易维护
<%String state = request.getParrameter("state" )%>
<td width="27"><input type="radio" name="state" value="AL" 〈%if(state.equal("AL")) out.print("checked")%〉/>
<td width="27"><input type="radio" name="state" value="MT" 〈%if(state.equal("MT")) out.print("checked")%〉/>
</td>
第二种方式:使用jsp标准标签库jstl:
首先需要加入库文件
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
其次为:
<td width="27">
<c:choose>
<c:when test="${state=='AL'}">
<input type="radio" name="state" value="AL" checked />
</c:when>
<c:otherwise>
<input type="radio" name="state" value="AL" />
</c:otherwise>
</c:choose>
<c:choose>
<td width="27">
<c:when test="${state=='MT'}">
<input type="radio" name="state" value="MT" checked />
</c:when>
<c:otherwise>
<input type="radio" name="state" value="MT" />
</c:otherwise>
</c:choose>
<c:choose>
</td>
其中state应该在request,session,等中赋值。
第三种方式:使用EL表达式:
<td width="27"><input type="radio" name="state" value="AL" ${(state=='AL')?'checked' : ''}/>
<td width="27"><input type="radio" name="state" value="MT" ${(state=='MT')?'checked' : ''}/>
</td>
显然使用EL表达式这种方式最简洁,不用写多余的代码。
以radiao 为例:
第一种方式:在jsp中使用java 脚本,这个方法最直接,不过脚本太多,不容易维护
<%String state = request.getParrameter("state" )%>
<td width="27"><input type="radio" name="state" value="AL" 〈%if(state.equal("AL")) out.print("checked")%〉/>
<td width="27"><input type="radio" name="state" value="MT" 〈%if(state.equal("MT")) out.print("checked")%〉/>
</td>
第二种方式:使用jsp标准标签库jstl:
首先需要加入库文件
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
其次为:
<td width="27">
<c:choose>
<c:when test="${state=='AL'}">
<input type="radio" name="state" value="AL" checked />
</c:when>
<c:otherwise>
<input type="radio" name="state" value="AL" />
</c:otherwise>
</c:choose>
<c:choose>
<td width="27">
<c:when test="${state=='MT'}">
<input type="radio" name="state" value="MT" checked />
</c:when>
<c:otherwise>
<input type="radio" name="state" value="MT" />
</c:otherwise>
</c:choose>
<c:choose>
</td>
其中state应该在request,session,等中赋值。
第三种方式:使用EL表达式:
<td width="27"><input type="radio" name="state" value="AL" ${(state=='AL')?'checked' : ''}/>
<td width="27"><input type="radio" name="state" value="MT" ${(state=='MT')?'checked' : ''}/>
</td>
显然使用EL表达式这种方式最简洁,不用写多余的代码。
相关文章推荐
- JSP的3种方式实现radio ,checkBox,select的默认选择值
- php select,radio和checkbox默认选择的实现方法
- Jquery操作radio,checkbox,select表单操作实现代码
- Jquery 选择 select 、radio 的几种方式
- jQuery获取Radio选择的Value值||两个select之间option的互相添加操作(jquery实现)
- jquery获取指定表格的指定列的值 以及 操作radio,checkbox,select表单操作实现代码
- php selectradio和checkbox默认选择的实现方法详解
- jQuery获取form中Select/textarea/checkbox/radio选择的Text和Value等其他常见操作
- jQuery设置 select、radio、checkbox 默认选中的值
- CheckBox jsp+javaScript多项选择checkbox取值实现
- 让DataGridViewCheckBoxColumn实现更复杂的选择方式
- 利用 window_onload 实现select默认选择
- jquery过滤选择常用radio,select,checkbox,input 等标签
- Jquery操作radio,checkbox,select表单操作实现代码
- ng1 select 默认选中第X项并且不会出现空白列的实现方式
- 利用 window_onload 实现select默认选择
- JSF2.0 SelectBooleanCheckbox在dataTable中实现全选,自定义选择多行操作
- Jquery操作radio,checkbox,select表单操作实现代码
- jsp中checkbox或select从后台获取值后默认选中的两种写法