jQuery:获取最后一行列选择器(jQuery: Get last row column selector)

编程入门 行业动态 更新时间:2024-10-28 02:28:26
jQuery:获取最后一行列选择器(jQuery: Get last row column selector)

我在表中有以下行:

<tr><td>Adric cut-out</td><td><span class="quantity">0</span></td><td>worthless</td></tr>

我已经选择了“数量”类的跨度,但我没有运气获得所选行中的最后一个TD元素。 我可以通过获取它的父级,然后是它的父级,然后是最后一个TD子元素来实现它,但是有更高效的东西吗?

以此为开头,我如何选择包含价格的TD元素? 请注意,它始终是该行的最后一项。

I have the following row in a table:

<tr><td>Adric cut-out</td><td><span class="quantity">0</span></td><td>worthless</td></tr>

I've already got the span with the class 'quantity' selected, but I'm having no luck getting the last TD element in the row selected. I can do it by getting its parent, then its parent, then the last TD child element but is there something a little more efficient?

Using this as a start, how would I select the TD element containing the price? Note, it will always be the last item on the row.

最满意答案

如果格式一致,那么升级到下一列应该相当有效:

var price = $('.quantity').closest('td').next().html();

简单地将一个类( price ?)分配给最后一个td并收集它可能会更快。

If the format is consistent, stepping up and over to the next column should be fairly efficient:

var price = $('.quantity').closest('td').next().html();

It might be faster to simply assign a class (price?) to the last td and collect that, though.

更多推荐

本文发布于:2023-07-15 05:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行列   选择器   jQuery   selector   column

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!