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

本文介绍了一种使用jQuery来获取HTML页面上被选中的单选按钮值的方法。通过绑定点击事件到单选按钮,当按钮被点击时会触发函数并显示该按钮对应的值。

5316

被折叠的 条评论
为什么被折叠?



