上传图片前预览

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>上传图片,测试</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <style type="text/css">
  /* 第二种方式  */
  #img02
  {
      filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
  };
 </style>
 <script type="text/javascript">
  // 第一种方式
  function showImage(){
   var fileName=document.getElementById("fname").value;
   var showFile=document.getElementById("img1");
   showFile.innerHTML="<img src=\"file:\\\\" + fileName + "\" width=\"80\" height=\"60\" />";
  }
  // 第二种方式
  function getValue(im){
   im.select(); 
   return document.selection.createRange().text;
  
  }
  function showImage02(imgFile){
//   var fileName=document.getElementById("fname02");
//   var fileValue=getValue(fileName);
   var file=getValue(imgFile);
   var showFile=document.getElementById("img02");
   showFile.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=file;
   showFile.style.width=300;
   showFile.style.height=200;
   
  }
 </script>
  </head>
 
  <body>
   <h1 style="color:red">第一种方式,测试,失败</h1>
    <form action="" enctype="multipart/form-data" method="post">
     上传图片:<input type="file" id="fname" onchange="showImage()"/><br>
     <img src="images\111.jpg" id="img1" name="img1"/><br>
     <input type="submit"/>
    </form>
    <hr>
    <h1 style="color:red">第二种方式,测试,可以</h1>
    <form action="" enctype="multipart/form-data" method="post">
     上传图片:<input type="file" id="fname02" onchange="showImage02(this)"/><br>
     <div id="img02"></div><br>
     <input type="submit"/>
    </form>
  </body>
</html>

你可能感兴趣的:(JavaScript,html,cache,css,Microsoft)