javascript jQuery:如何选择所有带有名称的单选按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7880829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery: How to select all radio buttons with a name?
提问by luqita
I am trying to select all radio buttons with a name, but I can only select the checked ones. For example this works:
我试图选择所有带有名称的单选按钮,但我只能选择选中的单选按钮。例如这有效:
$("input[@name='id']:checked").each(function() { // });
It selects all inputs with name id, which are checked (in this case one radio button). But I need all of them, as I need the not checked ones for this name, on this function.
它选择所有带有名称 id 的输入,这些输入被选中(在这种情况下是一个单选按钮)。但是我需要所有这些,因为我需要在这个函数上没有检查这个名字的那些。
This, for example, is not doing anything:
例如,这并没有做任何事情:
$("input[@name='id']").each(function() { // });
What do I do?
我该怎么办?
Thanks!
谢谢!
回答by jbabey
Try this instead:
试试这个:
$('input[name="yourName"]').each(function () { ... });
回答by Vikas Naranje
Try this
试试这个
$(':input[type="radio"]').each(function(index){
// YOUR CODE
});
above code will select all input element who's typeattribute is radio.
上面的代码将选择所有type属性为radio 的input 元素。
回答by Jayendra
Try -
尝试 -
$("input[name='id']").each(function() {
alert($(this).attr('name'));
});