图片预览

来源:互联网 发布:虚拟机mac os x 12 编辑:程序博客网 时间:2024/04/29 01:00

<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">

  <script language="JavaScript">
  <!--
   function pre(){
    var pos = document.all.f.value.lastIndexOf(".");
    var ext = document.all.f.value.substring(pos + 1,document.all.f.value.length);
    //alert(ext);
    if(ext.toLowerCase() == "jpg" || ext.toLowerCase() == "gif" || ext.toLowerCase() == "bmp" || ext.toLowerCase() == "png"){
     if(document.all.i){
      document.all.i.removeNode(true);
     }
     var img = document.createElement("<img>");
     img.id="i";
     img.src = document.all.f.value;
     document.all.img.appendChild(img);
    }else{
     alert("对不起,您上传的不是图片!");
    }
   }
  //-->
  </script>
 </head>

 <body>
  请选择图片:<input type="file" name="f" onchange="pre();">

  <div id="img"></div>
 </body>
</html>

原创粉丝点击