radio默认值
Html代碼
<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>
<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頁面最后面加入
?
方法2
要讓<html:radio>選擇很關鍵的一點,就是,這個JSP勢必對應的一個actionform吧,給它個初始值就OK了
默認值是動態的話
請注意到name屬性
性別
?
只要在request,session等范圍內存在user,這個上面的標簽就會根據consumptionClass.cco的值產生默認選中了
<html> <head> <title>初始化單選</title> <script> function initradio(rName,rValue){ var rObj = document.getElementsByName(rName); for(var i = 0;i < rObj.length;i++){ if(rObj[i].value == rValue){ rObj[i].checked = 'checked'; } } } </script> </head> <body> <form action="#"> 黑<input type="radio" name="tRadio" value="1"> 色<input type="radio" name="tRadio" value="2"> 頭<input type="radio" name="tRadio" value="3"> 發<input type="radio" name="tRadio" value="4"> </form> <script> initradio('tRadio',3); </script> </body> </html>?
<%@page pageEncoding="gbk"%> <html><head><title>Index</title><script type="text/javascript">function initradio(name,value){var r1=document.getElementsByName(name);for(var i=0;i<r1.length;i++){if(r1[i].value==value){r1[i].checked=true;}}}</script></head><body onload="initradio('r','<%=request.getParameter("value") %>')"><center><h1>Index</h1><hr><p>請選擇:</p><input type="radio" name="r" value="A">A<br><input type="radio" name="r" value="B">B<br><input type="radio" name="r" value="C">C<br><input type="radio" name="r" value="D">D<br></center></body> </html>?
?
?
總結
- 上一篇: session和cache的区别是什么?
- 下一篇: SCCM2012 RBA