许多父母的孩子jQuery Selector [英] Children of Many Parents jQuery Selector
问题描述
我正在尝试选择任何父级的每个第一个孩子,班级为 .Payment
I am trying to select every first child of any parent with the class .Payment
示例HTML:
<div class='payment'>
<input id="payments_0_:date_paid" name="payments[0][:date_paid]" type="text" />
<br>
<input id="payments_0_:amount_paid" name="payments[0][:amount_paid]" type="text" />
</div>
<div class='payment'>
<input id="payments_1_:date_paid" name="payments[0][:date_paid]" type="text" />
<br>
<input id="payments_1_:amount_paid" name="payments[0][:amount_paid]" type="text" />
</div>
<div class='payment'>
<input id="payments_2_:date_paid" name="payments[0][:date_paid]" type="text" />
<br>
<input id="payments_2_:amount_paid" name="payments[0][:amount_paid]" type="text" />
</div>
我如何遍历每个.payment并验证每个.payment中的第一个孩子是否属于一定品质?
How can I iterate through each .payment and validate whether the first child in each is under a certain quality?
这是我的尝试:
$.each($(".payment"), function(key, value) {
alert( $("value input:first").val() );
});
但我遇到的麻烦是使用var 值
获取该属性值()
But the trouble I am having here is using the var value
in getting that attribute value()
任何想法?
推荐答案
由于有问题的输入是第一个孩子,你可以使用 :first-child
选择器 (docs) ,然后使用原生值
获取其价值的属性:
Since the inputs in question are a first child, you can target them in the original selector using the :first-child
selector(docs) , then use the native value
property to get its value:
$('.payment > input:first-child').each(function() {
alert(this.value);
});
将它们减少到那些没有(或确实)满足验证的那些可能是值得的使用 filter()
(docs ) 方法或 not()
(docs) 方法。
It may be worthwhile to reduce them to a set of those that do not (or do) meet validation using the filter()
(docs) method or the not()
(docs) method.
这篇关于许多父母的孩子jQuery Selector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!