许多父母的孩子 jQuery 选择器
我正在尝试选择具有类 .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 中的第一个子级是否处于特定质量?
这是我的尝试:
$.each($(".payment"), function(key, value) {
alert( $("value input:first").val() );
});
但是我在这里遇到的麻烦是使用 var value
来获取该属性 value()
有什么想法吗?
I am trying to select every first child of any parent with the class .Payment
Sample 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>
How can I iterate through each .payment and validate whether the first child in each is under a certain quality?
This is my attempt :
$.each($(".payment"), function(key, value) {
alert( $("value input:first").val() );
});
But the trouble I am having here is using the var value
in getting that attribute value()
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于相关输入是第一个子项,因此您可以使用
:first-child
选择器(docs) ,然后使用本机value
属性获取其值:使用
将它们减少到一组不(或确实)满足验证的集合可能是值得的filter()
(docs) 方法或not()
(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 nativevalue
property to get its value: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 thenot()
(docs) method.不要使用
$.each()
,而是使用.each()
在 jQuery 选择上,这样你就可以访问$(this )
:Instead of using
$.each()
, use.each()
on the jQuery selection instead so you get access to$(this)
:尝试使用
$("input:first", value).val()
Try using
$("input:first", value).val()