<div class="htmlarea"><textarea id="runcode72146"> <title>Untitled Page</title> <title>JavaScript读取图片测试例子</title> <script language="javascript"><!-- var Gif=[["images/smilies/","victory","sweat","loveliness","call","handshake","kiss","time","hug","lol","mad","funk"] , ["images/default/","reply","newtopic","newspecial","star_level2","star_level2","top","star_level3","star_level2"]]; // 第一个是路径,后面的名称,比如 ["talk/",129,130,501,502,503] ,就是talk/ 目录下的129.gif,130.gif ...... 如果是字符串,就要加引号 var picType = ".gif"; //图片类型,如果你要显示所有类型图片,你可以把图片类型也放到数组里面 //加载图片主函数 function LoadGif() { document.body.insertAdjacentHTML("beforeEnd",'<div id="load" style="display=yes" style="display=yes"></script></textarea></div>'); var a = 0; var b = 1; Loading(a,b); } //显示加载失败信息 function Gif_Err() { alert("载入失败!") } //显示加载成功信息 function Gif_End() { alert("载入完成!") } //加载图片,并显示 function Loading(a,b) { //当数组元素为空时,切换数组的一维 if (!Gif[a][b]) { a++; b=1; } //当数组遍历完成后,显示图片 if (a==Gif.length) { Gif_End(); return; } //显示每次读取的图片 document.getElementById("load").innerHTML +='<img src="'+Gif%5Ba%5D%5B0%5D+Gif%5Ba%5D%5Bb++%5D+%20picType%20+%20'" onerror="Gif_Err()" alt="JavaScript 读取图片实例代码_javascript技巧" >'; //递归读取图片 Loading(a,b); } // --> <br><input onclick="runEx('runcode72146')" type="button" value="运行代码"> <input onclick="doCopy('runcode72146')" type="button" value="复制代码"> <input onclick="doSave(runcode72146)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]