如何在jQuery中获取复选框的值?
ask by maztt translate from soTo get the value of the Value attribute you can do something like this:
(要获取Value属性的值,您可以执行以下操作:)
$("input[type='checkbox']").val();
Or if you have set a class
or id
for it, you can:
(或者,如果您为其设置了class
或id
,则可以:)
$('#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
}