js或jquery怎么循环获取单选框选中的值,比如页面有8个单选框,一组2个,js如何循环获取选中值
1个回答
展开全部
看下吧 不懂留言
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="radio" name="a" value="a1">a1
<input type="radio" name="a" value="a2">a2
<br>
<input type="radio" name="b" value="b1">b1
<input type="radio" name="b" value="b2">b2
<br>
<input type="radio" name="c" value="c1">c1
<input type="radio" name="c" value="c2">c2
<br>
<input type="radio" name="d" value="d1">d1
<input type="radio" name="d" value="d2">d2
<br>
<button onclick="fn()">获取</button>
<script>
var inpArr = document.getElementsByTagName("input"),
result = ""
function fn(){
result = "";
for(var i=0;i<inpArr.length;i++){
if(inpArr[i].checked){
result+=inpArr[i].value+" ";
}
}
alert(result)
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询