单选框获取值

来源:互联网 发布:数据点阵笔考试 编辑:程序博客网 时间:2024/06/03 09:39
<script type="text/javascript">function getRadioValue() {if (jQuery('#a').is("input:checked")) {alert(jQuery('#a').val());} else if (jQuery('#b').is("input:checked")) {alert(jQuery('#b').val());}}$(document).ready(function() {$("#a").bind("click", getRadioValue);$("#b").bind("click", getRadioValue);});</script>
<body><input type="radio" id="a" name="radio" value="a" />a<input type="radio" id="b" name="radio" value="b" />b</body>