日期:2014-05-16  浏览次数:20381 次

使用js随机更换相对路径img下的0-count的jpeg图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
</head>
<body>
<div id="pic" style="FILTER:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);width:300px;height:200px;color:red;"></div>
<script>
var count=255;
var control=setInterval("showpic()",10);
function showpic(){
var errors=new Array();
for(i=0;i<count;i++){
  errors.push(true);
}
var e;
do{
  e="success"
  try{
    var position=parseInt(Math.random()*count);
    document.getElementById("pic").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src="img/"+position+".jpg";
  }catch(e){
    errors[position]=false;
if(hasNothing(errors)){
   document.getElementById("pic").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src="404.jpg";
   clearInterval(control);
   return;
}
  }
}while(e!="success");
error=null;
e=null;
}
function hasNothing(array){
  for(var subScript in array){
    if(array[subScript]){
  return false;
}
  }
  return true;
}
</script>
</body>
</html>