jQuery - prop(“checked”) - 所有复选框或仅“复选”

时间:2015-10-07 16:23:33

标签: jquery

考虑以下jQuery。代码是否会找到包含复选框的子元素($this),无论检查未选中,还是仅复选框checked

$this.find('input').prop("checked")

1 个答案:

答案 0 :(得分:4)

两者都不会找到input后代的所有$this元素,并返回第一个checked属性。

$this              // from "this" current element
  .find("input")   // find all "input" elements
  .prop("checked") // and return property of first one

如果要匹配所有选中的复选框,请改为:

$this.find(":checkbox:checked");
// or
$this.find("input[type=\"checkbox\"]").filter(":checked");
相关问题