我在stackoverflow中看到很多使用输入名称获取组无线电值的示例。有没有办法使用id找到它?
答案 0 :(得分:1)
通常最好使用名称,因为它可以让您知道组中的哪个单选按钮被选中(组中的所有单选按钮都具有相同的名称,但only one has a given id)。
但是如果你想检查你的身份证上是否有特定的单选按钮,你可以这样做:
var yesorno = document.getElementById('someId').checked;
如果您想获得您知道其身份的单选按钮的值,则只需
var value = document.getElementById('someId').value;
答案 1 :(得分:0)
简短回答,不是真的。
你必须有一个名字,否则单选按钮将无法一起工作,这意味着所有这些按钮都可以被检查。如果您已有名称,请按以下方式获取值:
$('[name="myGroup"]:radio:checked').val()
答案 2 :(得分:0)
我发现了自己。这段代码对我有用!
alert($('input[id=groudid]:checked').val());
答案 3 :(得分:0)
var name = $("#myId").attr("name")
$(":radio").filter(function(){return $(this).attr("name") == name}).filter(":checked").val()