jsp单选按钮默认选中的问题,

怎么默认选中第一个啊,我用的document.all("selected")[0].checked="checked";这句话在eclipse中是可以的,但是到了IE8里面有不行了,快整死我了
单选按钮是这样生成的,求大侠指点本人新手:
<%
while(rs.next()){
%>
<tr class="tbl_detail0">
<td rowspan="1" class="td_center">
<input value = "<%=rs.getString(1) %>" type="radio" name="selected" id="selected" / >
</td>
<td class="td_left"><%=rs.getString(1) %></td>
</tr>
<%
if(rs.next()){
%>
<tr class="tbl_detail1">
<td rowspan="1" class="td_center">
<input value = "<%=rs.getString(1) %>" type="radio" name="selected" id="selected" />
</td>
<td class="td_left"><%=rs.getString(1)%></td>
</tr>
<%
}
}
%>

checked 预先选定复选框或单选按钮。
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>你好</title>
</head>
<body>
<input type="radio" name="a" >喜欢
<input type="radio" name="a" checked>不喜欢
<input type="radio" name="a" >讨厌
<input type="radio" name="a" >很讨厌
</body>
</html>
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2018-03-02
document.all("selected")[0].checked="checked";你把这句改为
document.all("selected")[0].checked=true;
试试!追问

有个人让我从
document.all("selected")[0].checked=true;该过来的,也是不行啊

追答

你定义一个变量比如:i;
" type="radio" name="selected" id="selected" / >
在循环的时候i++;
这样就可以是radio的id = selected1,id = selected2等等了,因为id必须是唯一的。
然后在jsp中你直接找到这个id就可以了:
document.getElementById("select1").checked = true;

本回答被提问者和网友采纳
第2个回答  2013-03-15
<%
while(rs.next()){
%>
<tr class="tbl_detail0">
<td rowspan="1" class="td_center">
<input value = "<%=rs.getString(1) %>" type="radio" name="selected" id="selected" / >
</td>
<td class="td_left"><%=rs.getString(1) %></td>
</tr>
<%
int i=0;
if(rs.next()){
%>
<tr class="tbl_detail1">
<td rowspan="1" class="td_center">
<%if(i==0){%>
<input value = "<%=rs.getString(1) %>" type="radio" name="selected" id="selected" selected="true"/>
<%}{%>
<input value = "<%=rs.getString(1) %>" type="radio" name="selected" id="selected" />
<%}%>
</td>
<td class="td_left"><%=rs.getString(1)%></td>
</tr>
<%
i++;
}
}
%>
相似回答