Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 使用Jquery将表中的文本替换为数组_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用Jquery将表中的文本替换为数组

Javascript 使用Jquery将表中的文本替换为数组,javascript,jquery,html,Javascript,Jquery,Html,我使用的是jQueryV1.11.1,我想替换HTML表中从左起第三行开始的所有TD元素。我使用的数组必须在表的每个TD元素中传递值 var numberArray = [0,1,2,3,4,5]; $.each(numberArray , function(index, value){ $("table tr td:nth-child(3)").html(value); }); 这将在每个TD元素中返回一个5。如何将每个TD标签设置为1、2、3、4、5。试试这个 $("table

我使用的是jQueryV1.11.1,我想替换HTML表中从左起第三行开始的所有TD元素。我使用的数组必须在表的每个TD元素中传递值

var numberArray = [0,1,2,3,4,5];

$.each(numberArray , function(index, value){
    $("table tr td:nth-child(3)").html(value);
});
这将在每个TD元素中返回一个5。如何将每个TD标签设置为1、2、3、4、5。

试试这个

$("table tr td:nth-child(3)").each(function(index){
    $(this).html(numberArray[index]);
});
var numberArray = [0,1,2,3,4,5];

        $.each(numberArray , function(index, value){
            $("table tr td:nth-child("+index+")").html(value);
        });

如果要使用数组更新第三行的值,请尝试此代码

var numberArray = [0,1,2,3,4,5];
$.each(numberArray , function(index, value){
    var td=value+1;
    $("table tr:nth-child(3) td:nth-child("+td+")").html(value);
});
试试这个:

var numberArray = [0,1,2,3,4,5];
$.each(numberArray , function(index, value){
    $("table tr td:nth-child("+index+")").html(value);
});

您能提供您的HTML吗?“左起第三行”是指“列”吗?