The following is an online-picked article (not tested but canonical to imitate)
Copy Code code as follows:
<meta http-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 value does not change cannot be submitted");
Break
}
}
}
}
</script>
<body>
<form action= ' method= ' post ' onsubmit= ' Javascript:return check_radio () ' >
<input type= ' Radio ' value= ' 1 ' name= ' radio, ' checked= ' checked ' > A;
<input type= ' Radio ' value= ' 2 ' name= ' Radio ' > two;
<input type= ' Radio ' value= ' 3 ' name= ' Radio ' > three;
<input type= ' Radio ' value= ' 4 ' name= ' Radio ' > four;
<input type= ' Radio ' value= ' 5 ' name= ' Radio ' > five;
<input Type=submit value=sub >
</form>
</body>
The following is a value that does not choose to get radio
Copy Code code as follows:
<input type= "Radio" name= "Money" value= "1"/> USD
<input type= "Radio" name= "Money" value= "2"/> yen
<input type= "Radio" name= "Money" value= "3"/> Euro
Native JS mode: (native DOM operation will be the text as a node, so there will be nextsibling)
Copy Code code as follows:
var dollar = document.getelementsbyname ("Money") [0].nextsibling.nodevalue;
var yen = Document.getelementsbyname ("Money") [1].nextsibling.nodevalue;
var € = document.getelementsbyname ("Money") [2].nextsibling.nodevalue;
jquery Way
Copy Code code as follows:
$ (' input[name= ' money ']:checked '). Next (' span '). HTML ();
<input type= "Radio" name= "Money" value= "1" checked= "checked"/><span> USD </span>
<input type= "Radio" name= "Money" value= "2"/><span> yen </span>
<input type= "Radio" name= "Money" value= "3"/><span> Euro </span>
<!--normal, create a check box or a radio box to link it with a label, such as:-->
<input id= "Radio1" type= "Radio" name= "Money" value= "1"/><label for= "Radio1" > USD </label>
The following to select:
This only judge has no choice
Copy Code code as follows:
function Radiovalue () {
var Radarr = document.getelementsbyname ("Radiov");
var radvalue = "";
alert (radarr.length);
for (var i=0; i<radarr.length; i++) {
Alert (radarr[i].checked+ "" +radarr[i].name + "" + Radarr[i].value);
if (radarr[i].checked) {
Radvalue = Radarr[i].value;
}
}
if (radvalue!= null && radvalue!= "") {
alert (Radvalue);
}else{
Alert ("Please select");
}
}
<input type= "button" value= "Test radio Get Data" onclick= "Radiovalue ();" />