heisetoufa 发表于 2013-2-7 19:46:21

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").checked=true;//第一个radio选中}if("${consumptionClass}" == "赚了"){    document.all("consumptionClass").checked=true;//第二个radio选中}if("${consumptionClass}" == "借出"){    document.all("consumptionClass").checked=true;//第三个radio选中}if("${consumptionClass}" == "借入"){    document.all("consumptionClass").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/
页: [1]
查看完整版本: java js JavaScript 设置html:radio的默认选中, js也可以用el表达式