关于判断radiobutton抉择的js
关于判断radiobutton选择的js
现在我有个需求,就是想通过js来获取到我选择的value值是什么
<input type="radio" name="yhk" value="1001" checked="checked"/>
<input type="radio" name="yhk" value="1034" />
<input type="radio" name="yhk" value="1005" />
<input type="radio" name="yhk" value="1008" />
现在我怎么写JS,才能获取到我选中的那个radio的值
希望能写详细点哦
------解决方案--------------------
现在我有个需求,就是想通过js来获取到我选择的value值是什么
<input type="radio" name="yhk" value="1001" checked="checked"/>
<input type="radio" name="yhk" value="1034" />
<input type="radio" name="yhk" value="1005" />
<input type="radio" name="yhk" value="1008" />
现在我怎么写JS,才能获取到我选中的那个radio的值
希望能写详细点哦
------解决方案--------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="radio" name="yhk" value="1001" checked="checked"/>
<input type="radio" name="yhk" value="1034" />
<input type="radio" name="yhk" value="1005" />
<input type="radio" name="yhk" value="1008" />
<input type="button" onclick="cz();" value="获取radio选中的值">
<script>
function cz(){
var url = '';
var r=document.getElementsByName("yhk");
for(var i=0;i<r.length;i++){
if(r[i].checked){
alert(r[i].value);
}
}
}
</script>
</body>
</html>