在 jQuery 中获取复选框值 [英] Get checkbox value in jQuery

查看:20
本文介绍了在 jQuery 中获取复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 jQuery 中获取复选框的值?

How can I get a checkbox's value in jQuery?

推荐答案

要获取 Value 属性的值,您可以执行以下操作:

To get the value of the Value attribute you can do something like this:

$("input[type='checkbox']").val();

或者,如果您为它设置了 classid,您可以:

Or if you have set a class or id for it, you can:

$('#check_id').val();
$('.check_class').val();

然而,无论是否检查,这都会返回相同的值,这可能会令人困惑,因为它与提交的表单行为不同.

However this will return the same value whether it is checked or not, this can be confusing as it is different to the submitted form behaviour.

要检查它是否被选中,请执行:

To check whether it is checked or not, do:

if ($('#check_id').is(":checked"))
{
  // it is checked
}

这篇关于在 jQuery 中获取复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆