I have a several forms, and I'd like to select only the first and second input box of each form
$("form input:nth-child(1), form input:nth-child(2)");
开发者_运维知识库
But this doesn't work because each input has a label next to it, so there is no input that is nth-child(1)
.
Example at jsbin
You can do it using :lt()
, like this:
$("form input:lt(2)");
This selects all elements that match at less-than the passed index, the first and second elements are index 0 and 1, and will match this selector :)
You can use eq()
:
$("form input:eq(0), form input:eq(1)");
This selects the first and second of the matched elements.
精彩评论