简体   繁体   English

jQuery:如何选择具有名称的所有单选按钮?

[英]jQuery: How to select all radio buttons with a name?

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). 它选择具有名称id的所有输入,这些输入被检查(在这种情况下是一个单选按钮)。 But I need all of them, as I need the not checked ones for this name, on this function. 但是我需要所有这些,因为我需要这个名称的未检查的,在这个函数上。

This, for example, is not doing anything: 例如,这没有做任何事情:

$("input[@name='id']").each(function()  { // });

What do I do? 我该怎么办?

Thanks! 谢谢!

Try this instead: 试试这个:

$('input[name="yourName"]').each(function () { ... });

http://jsfiddle.net/sFtdR/ http://jsfiddle.net/sFtdR/

Try this 试试这个

$(':input[type="radio"]').each(function(index){
     // YOUR CODE
});

above code will select all input element who's type attribute is radio . 上面的代码将选择所有输入元素,其类型属性是radio

Try - 试试 -

$("input[name='id']").each(function()  { 
    alert($(this).attr('name'));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM