Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

  ask by maztt translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
288 views
Welcome To Ask or Share your Answers For Others

1 Answer

To 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:

(或者,如果您为其设置了classid ,则可以:)

$('#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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...