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

查看:73
本文介绍了在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();

或者如果您设置了 class id ,您可以:

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

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

但是,无论是否选中,都会返回 same 这可能会令人困惑,因为它与提交的表单行为不同。

However this will return the same value whether it is checked or not, this can be confusing as it is differnt 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天全站免登陆