Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何搜索表格并提取数据?_Javascript_Google Chrome Extension - Fatal编程技术网

Javascript 如何搜索表格并提取数据?

Javascript 如何搜索表格并提取数据?,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我是js新手,我正在开发一个chrome扩展,我对一个网站感到困惑。假设我有一个html格式的简单表,如下所示 <html> <body> <table class="birthdays"> <tbody><tr> <th>date</th> <th>month</th> <

我是js新手,我正在开发一个chrome扩展,我对一个网站感到困惑。假设我有一个html格式的简单表,如下所示

<html>
  <body>      
    <table class="birthdays">   
      <tbody><tr>
        <th>date</th>
        <th>month</th>
        <th>year</th>
      </tr> 
    
    <tr class="r0">
      <td>Person</td>
      <td>1</td>
      <td>Jan</td>
      <td>77</td>
      <td colspan="3"></td>
    </tr>
    <tr class="r0">
    <td>Person</td>
      <td>1</td>
      <td>Jan</td>
      <td>77</td>
      <td colspan="3"></td>
    </tr>
    </tbody></table>
  </body>
</html>

它说它找到了一个th对象,但没有给我实际的数据。这是第一个问题,我的实际目标是确定tr标记中的所有元素是否具有相同的属性(例如,如果每个人的生日都在1月,请打开一个选项卡)。

这不是一个完整的答案,但在javascript中,容器不是它的内容-即,您需要document.getElementsByTagName(“th”)[0][0].innerHTML获取“日期”字符串。

这不是一个完整的答案,但在javascript中容器不是它的内容-即,您需要document.getElementsByTagName(“th”)[0][0]。innerHTML获取“日期”字符串。

document.getElementsByTagName 返回HTMLCollection

它是一个类似数组的对象(不是真正的数组) 您可以通过调用
item()
方法从中获取值


似乎您需要类似于document.getElementsByTagName(“th”).item(0).innerHTML的内容来获取第一个th标记的内容 返回HTMLCollection

它是一个类似数组的对象(不是真正的数组) 您可以通过调用
item()
方法从中获取值


似乎您需要类似于document.getElementsByTagName(“th”).item(0).innerHTML的内容来获取第一个第th个标记的内容

如何查看我想要的所有标记的列表?我想用每个类的第三个元素创建一个列表。在这种情况下,最好使用选择器
document.querySelectorAll(“trtd:nth child(3)”)
如何查看我想要的所有标记的列表?我想用每个类的第三个元素创建一个列表。在本例中最好使用选择器
document.querySelectorAll(“trtd:nth child(3)”)
const x = document.getElementsByTagName("th")[0][0]
alert(x)