演示:http://jsfiddle.net/majidf/LhDXG/
标记
Sex:<br/> <input type="radio" name="gender" value="male" /> Male<br/><input type="radio" name="gender" value="female" /> Female<br/>Age group:<br/> <input type="radio" name="ageGroup" value="0-3" /> 0 to 3<br/><input type="radio" name="ageGroup" value="3-5" /> 3 to 5<br/><input type="radio" name="ageGroup" value="5-10" /> 5 to 10<br/><button onclick="getValues();">Get values</button>
JS
function getRVBN(rName) { var radioButtons = document.getElementsByName(rName); for (var i = 0; i < radioButtons.length; i++) { if (radioButtons[i].checked) return radioButtons[i].value; } return '';}function getValues() { var g = getRVBN('gender'); var a = getRVBN('ageGroup'); alert(g + ' ' + a);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)