日期:2014-05-18  浏览次数:20612 次

radio的回显问题,请大家帮忙啊
jsp页面中用到代码
<input   type= "radio "   name= "sex "   value= "1 "   checked> 男
<input   type= "radio "   name= "sex "   value= "0 "> 女

默认是男
但是保存到数据库中的是女的话,回显仍然是男
怎么办啊

------解决方案--------------------
大家帮忙啊
在线等
------解决方案--------------------
<input type= "radio "> 的value属性值要与数据库绑定。
------解决方案--------------------
<input type= "radio " name= "sex " value= "男 " > 男
<input type= "radio " name= "sex " value= "女 "> 女
------解决方案--------------------
jsp页面中用到代码
<input type= "radio " name= "sex " value= "1 " checked> 男/////////这里写死了它如何会变?
<input type= "radio " name= "sex " value= "0 "> 女

默认是男
但是保存到数据库中的是女的话,回显仍然是男
怎么办啊
/////////////////////////
直接BEAN的话:
<input type= "radio " name= "sex " value= "男 " <% "男 ".equals($bean.getSex())? " checked ": " "%> > 男
<input type= "radio " name= "sex " value= "女 " <% "女 ".equals($bean.getSex())? " checked ": " "%> > 女

用Struts标签的话:
<html:radio property= "sex " value= "男 "/>
<html:radio property= "sex " value= "女 "/>
它自己会处理默认选中,注意首先要保证你的这个BEAN方法返回的值一定是这里的可用值中的一个.否则一个都不会选中.

其它的类似原理.

------解决方案--------------------
这样来试看看:
假设你在数据中sex为性别;
<%
while(rs.next){
String sex=rs.getString( "sex ");
%>
<input type= "radio " name= "sex " value= "1 " <%if(sex==1) out.print( "checked ");%> > 男
<input type= "radio " name= "sex " value= "0 " <%if(sex==0) out.print( "checked ");%> > 女
<%}%>