<html>
<head>
<metahttp-equiv="Content-Type" content="text/html; charset=gb2312">
<title>text</title>
<script>
var chk = 0;
window.onload=function(){
var chkObjs=document.getElementsByName("radio");
for(var i=0;i<chkObjs.length;i++){
if(chkObjs[i].checked){
chk = i;
break;
}
}
}
function check_radio(){
var chkObjs=document.getElementsByName("radio");
for(var i=0;i<chkObjs.length;i++){
if(chkObjs[i].checked){
if(chk==i){
alert("radio值没有改变不能提交");
break;
}
}
}
}
</script>
</head>
<body>
<formaction='' method='post' onsubmit='javascript:return check_radio()'>
<inputtype='radio' value='1' name='radio' checked='checked'>一;
<inputtype='radio' value='2' name='radio'>二;
<inputtype='radio' value='3' name='radio'>三;
<inputtype='radio' value='4' name='radio'>四;
<inputtype='radio' value='5' name='radio'>五;
<inputtype=submit value=sub >
</form>
</body>
</html>
=============================================
另外,如果使用.net控件,仍然可以使用JS获取选中值,如:<asp:RadioButtonList ID="rblID" runat="server"RepeatColumns="7" RepeatLayout="Flow">
<asp:ListItem Value="1"Selected="True">选项一</asp:ListItem>
<asp:ListItemValue="2">选项二</asp:ListItem>
<asp:ListItemValue="3">选项三</asp:ListItem>
</asp:RadioButtonList>
注意各选项radio.ID的html生成规则分别为:rblID_0、rblID_1、rblID_2。即等同于:
<input id="rblID_0" type="radio" name="rblID"value="1" checked="checked" />
<input id="rblID_1" type="radio" name="rblID"value="2" />
<input id="rblID_2" type="radio" name="rblID"value="3" />