Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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_Jquery_Html - Fatal编程技术网

通过Javascript的多个图像?

通过Javascript的多个图像?,javascript,jquery,html,Javascript,Jquery,Html,我对这一点比较陌生,目前有两个例子: var img = new Image(); var div = document.getElementById('Latest_A'); img.onload = function() { Latest_A.appendChild(img); }; img.src = '../Latest_A.jpg'; 然后是另一个,B等等 目前它只调用最后一个实例?是否同时调用这两个或多个图像?我很确定您正在尝试从图像URL列表向同一元素添加多个图像

我对这一点比较陌生,目前有两个例子:

    var img = new Image();
var div = document.getElementById('Latest_A');

img.onload = function() {
  Latest_A.appendChild(img);
};

img.src = '../Latest_A.jpg';
然后是另一个,B等等


目前它只调用最后一个实例?是否同时调用这两个或多个图像?

我很确定您正在尝试从图像URL列表向同一元素添加多个图像

这将从数组中获取URL列表,并将每个URL添加到选定的div。它还将为每个URL分配一个唯一的id,以防您需要为每个URL设置样式

var div=document.getElementById'Latest_A'; var imageArray=['http://placehold.it/200x200','http://placehold.it/200x300','http://placehold.it/300x200','http://placehold.it/200x150']; 对于var i=0;i如果有更多的html,你能显示所有的JS吗?我建议在代码段或JSFIDLE上复制您的问题。保存元素的变量称为div,而不是Latest_a.So div.appendChildimg;。先生,你真了不起!非常感谢。