我在页面上有一些输入字段的“集合”,如下所示:
<div id="allthesets">
<div>
<input name="po-3" type="text">
<input name="ba-3" type="text">
</div>
<div>
<input name="po-9" type="text">
<input name="ba-9" type="text">
</div>
<div>
<input name="po-123" type="text">
<input name="ba-123" type="text">
</div>
</div>
<div id="rightafterthesets">
This is the div that comes right after the sets
</div>我正在尝试使用jquery获得最大的索引(在本例中是123)。请注意,每个集合都在一个div中,但这些div没有唯一的is。但是,所有的集合都包含在一个div中,紧跟在这个div之后的就是id="rightafterthesets"。因为最好的索引是最新的,如果我能想出备份的方法,我想rightafterthesets div可以帮助我获得最后的索引。
发布于 2009-10-06 14:26:33
var largestID = $("#allthesets div:last input:first").attr("name")这将获取allthesets div中的最后一个div,然后获取其中的第一个输入并获取其名称,在您提供的示例中为po-123
发布于 2009-10-06 22:28:03
我认为这应该是可行的:
$('#allthesets > div:last > input')https://stackoverflow.com/questions/1525906
复制相似问题