能预览Flash也可以预览图片

 

<input type="file" name="file1" style="width:300'" class="tx1" value="" onchange="PreviewImg(this);">
 
 <div style="width:400px;height:300px;border:1px solid #aaaaaa;overflow:auto" id="previewDiv">


 </div>

 


<script language="javascript">

function PreviewImg(obj){
  var div = document.getElementById("previewDiv");
  if(obj.value=="" || div.childNodes.length>0){
    div.removeChild(div.firstChild);
    if(obj.value=="")return;
  }
  var ext = obj.value.substring(obj.value.lastIndexOf(".")+1)
  div.appendChild(getFlash(obj.value,ext));
}
function getFlash(src,ext){
 var img;
 switch(ext.toLowerCase()){
  case "jpg":
  case "jpeg":
  case "bmp":
  case "gif":
  case "png":
   img = document.createElement("img");
   break;
  case "swf":
   img = document.createElement("embed");
   img.type="application/x-shockwave-flash";
   img.width=400;
   img.height=300;
   break;
 }
 img.src=src;
 return img;
}
</script>

posted @ 2010-03-26 10:40  Nina  阅读(343)  评论(0编辑  收藏  举报