如何在html表中查找单元格的子集?使用R或JQuery [英] How to find a subset of cells in an html table? using R or JQuery

查看:92
本文介绍了如何在html表中查找单元格的子集?使用R或JQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在html页面中,我有一个巨大的表(只有一个表),我只需要访问其中一个单元格.例如,以下代码是此表的两行,每行6列.

In an html page I have one huge table (only one table) and I need to access only one of the cells. For example the following code is two rows of this table with 6 columns.

<tr>
    <td>
      Type1                                                                    
    </td>
    <td>
      103
    </td>                                
    <td>                                    
      153                                                                        
    </td>                                
    <td>
      N/A
    </td>
    <td align = "center">
      NA
    </td>
    <td align = "center">
      1
    </td>
</tr>                            
<tr>
    <td>                                  
      Type2                                                                    
    </td>
    <td>
      0
    </td>                                
    <td>                                    
      220                                                                        
    </td>                                
    <td>
      243
    </td>
    <td align = "center">
      abc
    </td>
    <td align = "center">
      100
    </td>
</tr>

如何找到值"103"(行标题"Type1"的第二列)?如果不是这样,是否可以在R(XML库)中完成此操作,那么JQuery也可以.非常感谢.

How can I find the value "103" (the second column of the row header "Type1")? Is this possible to be done in R (XML library) if not JQuery would also be fine. Thanks much.

推荐答案

我误读/误解了您的要求.如果您想要值'103'并且拥有'Type1',则可以使用它在包含'Type1'的td之后返回td的值:

I misread/misunderstood what you were asking. If you want the value '103' and you have 'Type1' you can use this to return the value of the td after the td that contains 'Type1':

$("td:contains('Type1')").next("td").text()


我不确定R,但是在jQuery中有 :contains() :


I'm not sure about R, but in jQuery there's the :contains():

$("td:contains('103')")应该选择它.

这篇关于如何在html表中查找单元格的子集?使用R或JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆