簡體   English   中英

jQuery select:容器的最后一個孩子

[英]jQuery select :last-child of container

我在選擇一組div帶有表的所有最后輸入時遇到了麻煩。 這是我的問題的jsFiddle。

我的HTML結構的簡化版本:

<div class=".container">
  <table>
    <tbody>
      <tr>
        <td> <input /> </td>
        <td> <input /> </td> <!-- last input in container -->
      </tr>
    </tbody>
  </table>
</div>

<!-- More like this -->
<div class=".container"> ...

因此,如果我有5個.container則結果選擇將有5個input

我嘗試了以下選擇器:

$('.container input:last-child')

您可以選擇最后一個td並獲得其子輸入,例如:

var $inputs = $('.container td:last-child>input');

演示: https : //jsfiddle.net/bonh4r0g/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM