zoukankan      html  css  js  c++  java
  • 图片预览

     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     2 <html>
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     5 <script type="text/javascript">
     6 /**
     7 * 从 file 域获取 本地图片 url
     8 */
     9 function getFileUrl(sourceId) {
    10 var url;
    11 if (navigator.userAgent.indexOf("MSIE")>=1) { // IE
    12 url = document.getElementById(sourceId).value;
    13 } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox
    14 url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
    15 } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome
    16 url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
    17 }
    18 return url;
    19 }
    20 
    21 /**
    22 * 将本地图片 显示到浏览器上
    23 */
    24 function preImg(sourceId, targetId) {
    25 var url = getFileUrl(sourceId);
    26 var imgPre = document.getElementById(targetId);
    27 imgPre.src = url;
    28 }
    29 </script>
    30 </head>
    31 <body>
    32 <form action="">
    33 <input type="file" name="imgOne" id="imgOne" onchange="preImg(this.id,'imgPre');" />
    34 <img id="imgPre" src="" width="300px" height="300px" style="display: block;" />
    35 </form>
    36 </body>
    37 </html> 
  • 相关阅读:
    bzoj 4017: 小Q的无敌异或
    [TJOI2014] Alice and Bob
    [TJOI2014] 上升子序列
    bzoj 3261: 最大异或和
    bzoj3087: Coci2009 misolovke
    bzoj3521: [Poi2014]Salad Bar
    bzoj4032: [HEOI2015]最短不公共子串
    bzoj1027: [JSOI2007]合金
    bzoj4637: 期望
    bzoj3919: [Baltic2014]portals
  • 原文地址:https://www.cnblogs.com/itboy-2009/p/4553903.html
Copyright © 2011-2022 走看看