<%
//标志量判断哪个被选
boolean flag;
//从R1组里获取组中的VALUE值
String radGroup = request.getParameter("r1");
//用其中一个比较,相当于给FLAG赋值
flag="boy".equals(radGroup);
%>
<script language="javascript">
function gocheck() {
var a=document.getElementsByName("r1")
for (i=0;i<a.length;i++){
if (a[i].checked){
alert(a[i].value)
}
}
}
</script>
<html>
<body>
<input type="submit" name="button" value="button" οnclick="gocheck();">
<input type="radio" name="r1" value="boy" <%=flag?"checked":"" %> >
<input type="radio" name="r1" value="girl" <%=flag?"":"checked" %> >
</body>
</html>