Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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 如何制作html内容数组?_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript 如何制作html内容数组?

Javascript 如何制作html内容数组?,javascript,jquery,arrays,Javascript,Jquery,Arrays,以下是HTML: <table> <tbody> <tr> <td>1</td> <td>one</td> </tr> <tr> <td>2</td> <td>two</td> </tr> </tbody> </table&g

以下是HTML:

<table>
  <tbody>
    <tr>
      <td>1</td>
      <td>one</td>
    </tr>
    <tr>
      <td>2</td>
      <td>two</td>
    </tr>
  </tbody>
</table>
我该怎么做


我可以像这样选择表:
$('table')
并获得它的内容:
$('table td+td')
,但我不知道如何创建它们的数组。

您可以使用
:nth-child()
选择second
td
map()
返回数组

试试这个:

使用
$(“表td:nth child(2)”)。each()
循环遍历所有第二个td,并使用
.text()


您是否应该将其标记为重复?
var arr = ['one', 'two'];
var arr = $('table td:nth-child(2)').map(function() {
  return $(this).text();
}).get();
var arr = new Array();
$("table td:nth-child(2)").each(function(i){
  arr[i] = $(this).text();
})