【问题标题】:Using dom to get content from table with no id使用 dom 从没有 id 的表中获取内容
【发布时间】:2016-12-21 22:18:56
【问题描述】:

我不知道如何从没有 ID 的表中获取值。

我想使用 DOM 从

中获取值“03”
<tr><th scope='row'>Total WUs</th><td>03</td></tr>

但该表没有 ID。它是页面上的第一个表。我将给出整个表格的代码打印输出:

<table cellspacing='0' rules='all' border='1' style='border-collapse:collapse;'><tr><th scope='row'>User Name</th><td>laughing_squid</td></tr><tr><th scope='row'>Project Rank</th><td>1,156,036</td></tr><tr><th scope='row'>Team Rank</th><td>2</td></tr><tr><th scope='row'>Total Points</th><td>207</td></tr><tr><th scope='row'>Total WUs</th><td>03</td></tr><tr><th scope='row'>Points Yesterday</th><td>NA</td></tr><tr><th scope='row'>Points Today</th><td>69</td></tr><tr><th scope='row'>PPD Average</th><td>138</td></tr></table>

【问题讨论】:

    标签: dom html-table


    【解决方案1】:

    看看这个,这个脚本使用JQuery,可以从here下载:

    $('table td').each(function(){
      console.log($(this).text());
    });
    

    如果您只需要值 03,请使用以下值:

    console.log($('table td:eq(4)').text());
    

    【讨论】:

    • 我可以在 php 脚本中而不是控制台窗口中执行此操作,它会给我一个值吗?你有什么好的链接可以了解它吗?
    猜你喜欢
    • 2020-07-05
    • 2016-04-05
    • 1970-01-01
    • 2014-11-19
    • 2011-01-06
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多