如何整合一系列图像以形成HTML页面?

时间:2010-10-25 12:44:39

标签: javascript html5

我在一个文件夹中有一系列图像(名为image_1.jpg,image_2.jpg等)。如何将所有图像连接在一起以使用Javascript形成HTML页面?

1 个答案:

答案 0 :(得分:0)

只需添加:

<img src="path/to/your/image_1" alt="image_1" />
<img src="path/to/your/image_2" alt="image_2" />
<img src="path/to/your/image_3" alt="image_3" />

等...

编辑:

for(var i = 1 ; i < TOTAL_IMAGES ; i ++ )
{
  var img = document.createElement('img');
  img.src = "path/to/your/image_" + i;
  img.alt = "image number " + i;
  document.appendChild(img);  // this will append the image to the root element. You might want to use a <div> or something instead.
}