java js JavaScript 设置html:radio的默认选中, js也可以用el表达式


<html:radio property="consumptionClass" value="花了" >花了</html:radio>
<html:radio property="consumptionClass" value="赚了" >赚了</html:radio>
<html:radio property="consumptionClass" value="借出" >借出</html:radio>
<html:radio property="consumptionClass" value="借入" >借入</html:radio>


方法1

在jsp页面最后面加入



<script>

alert("${consumptionClass}");

if("${consumptionClass}" == "花了")
{
document.all("consumptionClass")[0].checked=true;//第一个radio选中
}
if("${consumptionClass}" == "赚了")
{
document.all("consumptionClass")[1].checked=true;//第二个radio选中
}
if("${consumptionClass}" == "借出")
{
document.all("consumptionClass")[2].checked=true;//第三个radio选中
}
if("${consumptionClass}" == "借入")
{
document.all("consumptionClass")[3].checked=true;//第四个radio选中
}
</script>



方法2

要让<html:radio>选择很关键的一点,就是,这个JSP势必对应的一个actionform吧,给它个初始值就OK了

默认值是动态的话

请注意到name属性

性别

<html:radio value="花了" property="consumptionClass" name="cco">花了</html:radio>
<html:radio value="赚了" property="consumptionClass" name="cco">赚了</html:radio>
<html:radio value="借出" property="consumptionClass" name="cco">借出</html:radio>
<html:radio value="借入" property="consumptionClass" name="cco">借入</html:radio>


只要在request,session等范围内存在user,这个上面的标签就会根据consumptionClass.cco的值产生默认选中了

黑色头发:http://heisetoufa.iteye.com/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值