Javascript 使用jquery获取类相同的td的最后一个值

Javascript 使用jquery获取类相同的td的最后一个值,javascript,jquery,Javascript,Jquery,我正在使用jQuery。我有如下html代码: <table> <tr> <td class="price">price</td> <td class="total">10 Rs</td> </tr> <tr> <td class="price">Total:</td> <td class="total">1

我正在使用jQuery。我有如下html代码:

<table>
   <tr>
     <td class="price">price</td>
     <td class="total">10 Rs</td>
   </tr>
   <tr>
     <td class="price">Total:</td>
     <td class="total">100 Rs</td>
   </tr>
</table>
现在,我只希望总价为100卢比。那么我应该写什么代码来解决这个问题呢?

试试这个

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>last demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<table>
  <tr>
    <td class="price">price</td>
    <td class="total">10 Rs</td>
  </tr>
  <tr>
    <td class="price">Total:</td>
    <td class="total">100 Rs</td>
 </tr>
</table>

<script>
  alert($( "tr td:last" ).text());
 </script>

</body>

$'.total:last'.text^就这么简单。您可以对特定元素$'使用eq。total:eq1'.text,