Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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 我想在“中加载图像”;波浪;。。 img{ 宽度:150px; 高度:150像素; 浮动:左; } var img=未定义, section=document.querySelector('section'), 图像=[ "http://www.psdgraphics.com/file/red-number-0.jpg", "http://www.psdgraphics.com/file/red-number-1.jpg", "http://www.psdgraphics.com/file/red-number-2.jpg", "http://www.psdgraphics.com/file/red-number-3.jpg", "http://www.psdgraphics.com/file/red-number-4.jpg", "http://www.psdgraphics.com/file/red-number-5.jpg", "http://www.psdgraphics.com/file/red-number-6.jpg" ]; 函数loadImage(i){ img=document.createElement('img'); 第三节儿童(img); img.dataset['index']=i; img.src=图像[i]; } 对于(var i=0;i_Javascript_Arrays - Fatal编程技术网

Javascript 我想在“中加载图像”;波浪;。。 img{ 宽度:150px; 高度:150像素; 浮动:左; } var img=未定义, section=document.querySelector('section'), 图像=[ "http://www.psdgraphics.com/file/red-number-0.jpg", "http://www.psdgraphics.com/file/red-number-1.jpg", "http://www.psdgraphics.com/file/red-number-2.jpg", "http://www.psdgraphics.com/file/red-number-3.jpg", "http://www.psdgraphics.com/file/red-number-4.jpg", "http://www.psdgraphics.com/file/red-number-5.jpg", "http://www.psdgraphics.com/file/red-number-6.jpg" ]; 函数loadImage(i){ img=document.createElement('img'); 第三节儿童(img); img.dataset['index']=i; img.src=图像[i]; } 对于(var i=0;i

Javascript 我想在“中加载图像”;波浪;。。 img{ 宽度:150px; 高度:150像素; 浮动:左; } var img=未定义, section=document.querySelector('section'), 图像=[ "http://www.psdgraphics.com/file/red-number-0.jpg", "http://www.psdgraphics.com/file/red-number-1.jpg", "http://www.psdgraphics.com/file/red-number-2.jpg", "http://www.psdgraphics.com/file/red-number-3.jpg", "http://www.psdgraphics.com/file/red-number-4.jpg", "http://www.psdgraphics.com/file/red-number-5.jpg", "http://www.psdgraphics.com/file/red-number-6.jpg" ]; 函数loadImage(i){ img=document.createElement('img'); 第三节儿童(img); img.dataset['index']=i; img.src=图像[i]; } 对于(var i=0;i,javascript,arrays,Javascript,Arrays,只需为onload处理程序分配一个伪递归回调: <html> <section> <style> img{ width: 150px; height:150px; float:left; } </style> </section> <script> var img = undefined, section = document.querySelector('section'), images=[

只需为onload处理程序分配一个伪递归回调:

<html>
<section>

<style>
img{
 width: 150px;
 height:150px;
 float:left;
 }
 </style>
 </section>


 <script>

 var img = undefined,
 section = document.querySelector('section'),
 images=[
 "http://www.psdgraphics.com/file/red-number-0.jpg",
 "http://www.psdgraphics.com/file/red-number-1.jpg",
 "http://www.psdgraphics.com/file/red-number-2.jpg",
 "http://www.psdgraphics.com/file/red-number-3.jpg",
 "http://www.psdgraphics.com/file/red-number-4.jpg",
 "http://www.psdgraphics.com/file/red-number-5.jpg",
 "http://www.psdgraphics.com/file/red-number-6.jpg"
  ];

  function loadImage( i ){
   img = document.createElement('img');
   section.appendChild(img);
   img.dataset['index'] = i;
   img.src=images[i];
 }
 for(var i=0;i<images.length;i++){

  loadImage(i)

  }

  </script>


  </html>
或者使用一些新的ES 7材料:

function loadImage( i ){
  if(i >= images.length) return;
  var img = document.createElement('img');
  section.appendChild(img);
  img.dataset['index'] = i;
  img.src=images[i];
  img.onload = () => loadImage(i+1);
}

loadImage(0);
(异步函数(){
对于(var i=0;iimage.onload=r);
}
})()

可能一些
setTimeout
以及递归可以提供很好的效果:

var img=未定义,
section=document.querySelector('section'),
图像=[
"http://www.psdgraphics.com/file/red-number-0.jpg",
"http://www.psdgraphics.com/file/red-number-1.jpg",
"http://www.psdgraphics.com/file/red-number-2.jpg",
"http://www.psdgraphics.com/file/red-number-3.jpg",
"http://www.psdgraphics.com/file/red-number-4.jpg",
"http://www.psdgraphics.com/file/red-number-5.jpg",
"http://www.psdgraphics.com/file/red-number-6.jpg"
];
函数loadImage(i){
img=document.createElement('img');
第三节儿童(img);
img.dataset['index']=i;
img.src=图像[i];
}
var指数=0;
函数loadNext(){
如果(索引
img{
宽度:150px;
高度:150像素;
浮动:左;
}


可能重复的
onloaf
-yummmm@ochi是的,对不起,在写作时被打断了:/不用担心…没什么大不了的…只是在打字错误上开个玩笑…:)A(通常是面包)会是一件很好吃的东西(它会很好很暖和)。所以一个
onloaf
事件,嗯……)
(async function(){

 for(var i = 0; i < images.length; i++){
  var img = document.createElement('img');
  section.appendChild(img);
  img.dataset['index'] = i;
  img.src=images[i];

  await new Promise(r => image.onload = r );
 }

 })()