上传图片前预览

<%@ 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" οnchange="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" οnchange="showImage02(this)"/><br>
     <div id="img02"></div><br>
     <input type="submit"/>
    </form>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值