Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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 从阵列到每个td单元iof表的数据_Javascript_Jquery - Fatal编程技术网

Javascript 从阵列到每个td单元iof表的数据

Javascript 从阵列到每个td单元iof表的数据,javascript,jquery,Javascript,Jquery,我有一个表,希望将数据从数组传递到每个单元格。一个单元格中只有一个数据 <table style="border: 1px solid #333"> <tr> <th>#1</th> <th>#2</th> <th>#3</th> <th>#4</th> <th>#5</th>

我有一个表,希望将数据从数组传递到每个单元格。一个单元格中只有一个数据

  <table style="border: 1px solid #333">
    <tr>
      <th>#1</th>
      <th>#2</th>
      <th>#3</th>
      <th>#4</th>
      <th>#5</th>
      <th>#6</th>
    </tr>
    <tr>
      <td></td>
      <td></td> 
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
</table>

你能寻求帮助吗?谢谢

您需要在每次迭代中使用正确的选择器以目标tds。使用
.eq()
选择器以及每个iTartion的索引属性可以执行以下操作:

var pole = [11,22,31,4,5,6];
 $.each(pole, function(i, val){
 $('table td').eq(i).html(val);
});

试试这个:


对当前对象使用此

 var pole = [11,22,31,4,5,6];
  $("table tr td").each(function(i, val){
    $(this).html(pole[i]);
  });

在javascript中,通过id获取元素,然后用td标记和所需的值替换innerHTML。

此外,您可以直接使用
val
而不是调用
pole[i]
$(document).ready(function(){

      var pole = [11,22,31,4,5,6];
      $.each(pole, function(i, val){
        $('table td').eq(i).html(pole[i]);
      });
    });
 var pole = [11,22,31,4,5,6];
  $("table tr td").each(function(i, val){
    $(this).html(pole[i]);
  });