<script>
var files = new Array(
"A.JPG","B.JPG");
var files_con = 1;
</script>
<div id="view"><script>
function od(){
if(this.clientWidth/document.body.clientWidth>this.clientHeight/document.body.clientHeight){this.width=(document.body.clientWidth-document.body.leftMargin*2)}else{this.height=(document.body.clientHeight-document.body.topMargin*2-4)}
}
document.write('<img id=aa src="'+files[files_con]+'"onload=od()>');</script>
</div>
<script for=document event=onkeypress language=javascript>
if(files_con < files.length) {
  view.innerHTML += files[files_con]+"<br>";
  document.all.aa.src="a.jpg"
  files_con++;
}
</script>

解决方案 »

  1.   

    对不起,是我没有表达清楚,因为上边的代码中a.jpg,b.jpg是我假设的,实际运用中,文件数不定,文件名不定!!!
      

  2.   

    <script>
    var files = new Array(
    "A.JPG","B.JPG");
    FILECOUNT=2
    //FILECOUNT是文件的总个数;
    function onkeydown(){var r=Math.round(Math.random()*FILECOUNT); 
    document.all.myimg.src=files[r] ;
    //如果文件名是一个数组的话,你就用随机数来读取数组的呀
    }
    </script>
    <body onkeydown='onkeydown();'>
    <img id=myimg src='a.jpg'>
    </body>