+
95
-

回答

使用jquery的filter方法,代码如下

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BFW NEW PAGE</title>
<script id="bfwone" data="dep=jquery.17&err=0" type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
<script type="text/javascript">
bready(function() {
$("#go").click(function() {

var val = $('input[name="test"]').filter(":checked").val();
//如果是id,就改成$('input[id="test"]')
if (typeof(val) == "undefined") {
alert("未选择");

} else {
alert("已选中"+val);
}
});
});
</script>
<style>
</style>
</head>
<body>
<input type="radio" value="1" name="test" />1
<input type="radio" value="2" name="test" />2
<input type="radio" value="3" name="test" />3
<input type="button" id="go" value="提交" />
</body>
</html>


网友回复

我知道答案,我要回答