function foo(){
var ele = document.getElementsByName("radioElement");
for(var i = 0;i<ele.length;i++){
if(ele[i].checked){
alert(i+"---->"+ele[i].value);
}
}
}
<body>
<form onsubmit="return foo();">
<input type="radio" name="radioElement">a</input>
<input type="radio" name="radioElement">b</input>
<input type="radio" name="radioElement">c</input>
<input type="radio" name="radioElement">d</input>
<input type="radio" name="radioElement">e</input>
<input type="submit" name="提交">
</form>
</body>
时间: 2024-11-06 18:10:29