zoukankan      html  css  js  c++  java
  • 简单实现JS上传图片预览功能

    HTML代码
    <div class="upload">
        <input type="button" class="btn" onclick="browerfile.click()" value="上传">
        <input type="file" id="browerfile" style="display: none;" class="test">
        <div class="img_center">
          <img src="" class="img1-img">
        </div>
      </div>
     
    实现功能的js代码
    //获取图片路劲的方法,兼容多种浏览器,通过createObjectURL实现
    function getObjectURL(file){
      var url = null;
      if(window.createObjectURL != undefined){
        url = window.createObjectURL(file);//basic
      }else if(window.URL != undefined){
        url = window.URL.createObjectURL(file);
      }else if(window.webkitURL != undefined){
        url = window.webkitURL.createObjectURL(file);
      }
     
      return url;
    }
     
    //实现功能代码
    $(function(){
      $("#browerfile").change(function(){
        var path = browerfile.value;
        var objUrl = getObjectURL(this.files[0]);
        if(objUrl){
          $('.img1-img').attr("src",objUrl);
        }
      })
    })
    

      


  • 相关阅读:
    ObjectiveC分类
    显示时间格式
    js模拟签名
    安装卸载homebrew
    NSFastEnumeration
    拼接音频
    在Orchard模块中访问模块本地的AppSettings
    重装证书
    msysgit中文问题
    Apple Push Notification service
  • 原文地址:https://www.cnblogs.com/wangzhuxing/p/7799841.html
Copyright © 2011-2022 走看看