我在表中有以下行:
<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.
更多推荐
发布评论