如何获取选定的输入:radio

发布于 2024-10-06 19:09:52 字数 137 浏览 0 评论 0原文

怎么会这样呢。

$('input:checked')

这不会吗?

$('input').is(':checked')

谢谢。

How come this works.

$('input:checked')

and this won't?

$('input').is(':checked')

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梓梦 2024-10-13 19:09:52

第二个版本应该使用.filter()而不是.is()

$('input').filter(':checked')

似乎 .is() 应该可以工作,因为有 a .not() 方法。但.not()实际上与.filter()相反。

The second version should use .filter() instead of .is().

$('input').filter(':checked')

It seems like .is() should work since there's a .not() method. But .not() is actually the opposite of .filter().

黒涩兲箜 2024-10-13 19:09:52

您想检查页面上的任何单选按钮是否被选中?无需这样做,总有一个被选中(单选按钮 = 恰好选择了一个选项)。

想要测试是否选择了具有特定 ID 的单选按钮?

$('#your-radio-button').is(':checked')

想要所有选中的单选按钮的列表吗?这将返回一个包含无线电输入的 jQuery 对象。

$('input:radio:checked')

如果您想将其限制为具有特定名称的输入:

$('input[name=something]:radio:checked')

You want to check if any radio button on the page is selected? No need to do that, there's always one that's selected (radio button = exactly one option selected).

Want to test if a radio button with a certain ID is selected?

$('#your-radio-button').is(':checked')

Want a list of all checked radio buttons? This returns a jQuery object containing the radio inputs.

$('input:radio:checked')

If you want to restrict it to inputs with a certain name:

$('input[name=something]:radio:checked')
韬韬不绝 2024-10-13 19:09:52

定义作品。一个返回列表,另一个返回布尔值。

Define works. One returns a list and the other returns a boolean.

独孤求败 2024-10-13 19:09:52

你可以试试这个。它有效并且有效。也测试过。

$("input[type=radio]:checked").val()

$("input:radio:checked").val()

$("input:radio").filter(":checked").val()

或者
您可以从此示例获得帮助
http://daxpanganiban.com/javascript/get-value-of -radio-button-using-jquery

干杯!

You can try this one.Its worked & tested also.

$("input[type=radio]:checked").val()

$("input:radio:checked").val()

$("input:radio").filter(":checked").val()

Or
You can get help from this sample
http://daxpanganiban.com/javascript/get-value-of-radio-button-using-jquery

Cheers!

暗喜 2024-10-13 19:09:52

试试这个:

$('input[name='radioName']:checked')

Try this:

$('input[name='radioName']:checked')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文