你不想要.is
; .is
测试条件并返回布尔值。使用.filter
获取匹配项:
$(this).prevAll("input").slice(-5).filter(":checked").length
.is()
根据集合中的任何元素是否与选择器匹配而不是元素集本身来返回true / false。
您可能打算使用.filter()
代替,它返回一组与您的选择器匹配的元素:
$(this).prevAll("input").slice(-5).filter(":checked").length