定義Foo() 函數,彈出對話框提示當前選中的是第幾個單選框

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>orm

相關文章
相關標籤/搜索