Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.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/68.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 TypeError:Node.appendChild的参数1不是对象_Javascript_Jquery - Fatal编程技术网

Javascript TypeError:Node.appendChild的参数1不是对象

Javascript TypeError:Node.appendChild的参数1不是对象,javascript,jquery,Javascript,Jquery,我试图用jQuery输出数据[0]的内容,但出现了此错误 TypeError:Node.appendChild的参数1不是对象 有什么想法吗 $('<div>').append(function () { if (data[0].length != 0) { var $container = $('<div></div>'); $.each(data[0], function(val) { $c

我试图用jQuery输出数据[0]的内容,但出现了此错误

TypeError:Node.appendChild的参数1不是对象

有什么想法吗

$('<div>').append(function () {

    if (data[0].length != 0) {
        var $container = $('<div></div>');
        $.each(data[0], function(val) {
            $container.append(
                $('<div>').html(data[val][0]),
                $('<div>').html(data[val][1]),
                $('<div>').html(data[val][2])
            )
        });
        return $container.html();
    }

})
$('').append(函数(){
如果(数据[0]。长度!=0){
变量$container=$('');
$.each(数据[0],函数(val){
$container.append(
$('').html(数据[val][0]),
$('').html(数据[val][1]),
$('').html(数据[val][2])
)
});
返回$container.html();
}
})

大概是.html(数据[0][val][0])?请给出数据对象的示例。

如果数据没有长度,请尝试返回空字符串

$('<div>').append(function () {

    if (data[0].length != 0) {
        var $container = $('<div></div>');
        $.each(data[0], function(val) {
            $container.append(
                $('<div>').html(data[val][0]),
                $('<div>').html(data[val][1]),
                $('<div>').html(data[val][2])
            )
        });
        return $container.html();
    }
    return '';    
});
$('').append(函数(){
如果(数据[0]。长度!=0){
变量$container=$('');
$.each(数据[0],函数(val){
$container.append(
$('').html(数据[val][0]),
$('').html(数据[val][1]),
$('').html(数据[val][2])
)
});
返回$container.html();
}
返回“”;
});
使用此功能时从附加文档:

返回要在每个元素末尾插入的HTML字符串、DOM元素或jQuery对象的函数


我相信这个问题可能与未返回任何内容以及解析器无法确定类型有关

在return语句之前添加console.log($container.html()),您得到了什么?我无法重现这个问题。你确定是从这个地方来的吗?这段代码似乎不会导致此问题。您不会在
else
条件中返回任何内容。这将永远不会起作用。您正在引用
数据[0]
(例如
数据[0][0]
数据[0][1]
)的每个索引,作为数据中的索引(例如
数据[0]
数据[1]
)。因为数据[0]的长度为n,但这并不意味着数据的长度也为n。如果您希望此数据可以修复,请显示数据的内容。很抱歉,不起作用:(然后需要在类似jsfiddle.netI的演示沙箱中重现您的问题我投票支持您的帮助,但我真的很支持打断您,因为我的问题真的很愚蠢…问题是忘记将[0]放入数组$('').html(数据[0][val][0]),这确实有效,为这篇帖子感到抱歉,我真的很疲惫。这家伙给我的解决问题的方法是放弃将[0]放入数组$('').html(数据[0][val][0]),这确实有效,为这篇帖子感到抱歉,我真的很疲惫……有时我们需要另一只眼睛;)