cnqncom
V2EX  ›  jQuery

问个 JQ 的选择节点的问题

  •  
  •   cnqncom · Jun 30, 2017 · 5690 views
    This topic created in 3286 days ago, the information mentioned may be changed or developed.
    <table>
    <tr>
    <td>1.1</td>
    <td>1.2</td>
    <td>1.3</td>
    </tr>
    <tr>
    <td>2.1</td>
    <td>2.2</td>
    <td>2.3</td>
    </tr>
    <tr>
    <td>3.1</td>
    <td>3.2</td>
    <td>3.3</td>
    </tr>
    </table>




    想通过 JQERY 同时选择上面表格的中每行第 2 个 TD,加上合适的 CLASS。
    $("table tr td:eq(1)").attr("class","hidden-xs");


    总是选择的第一个 TR 中的 1.2TD,下面两行没有被选中。这个表格可能有很多行,我需要选中每行第 2 个 TD。怎么做?
    7 replies    2017-06-30 22:08:30 +08:00
    zhlssg
        1
    zhlssg  
       Jun 30, 2017
    伪类选择器 nth-child
    vincedd
        2
    vincedd  
       Jun 30, 2017
    $("table tr td:nth-child(2)")
    cnqncom
        3
    cnqncom  
    OP
       Jun 30, 2017
    谢谢
    freestyleyooo
        4
    freestyleyooo  
       Jun 30, 2017 via Android
    马里奥
    zonzin
        5
    zonzin  
       Jun 30, 2017 via Android
    那种 json 的文件 JQ 如何处理呢?采集遇到的问题
    ijimmy
        6
    ijimmy  
       Jun 30, 2017 via iPhone
    @zonzin json 直接 eval 就是了啊,关 jq 什么事?
    dablwow
        7
    dablwow  
       Jun 30, 2017 via Android
    @zonzin 加载完了解析薄,这是原生 js 相关的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 23:54 · PVG 07:54 · LAX 16:54 · JFK 19:54
    ♥ Do have faith in what you're doing.