zoukankan      html  css  js  c++  java
  • html上传图片后,在页面显示上传的图片

    html上传图片后,在页面显示上传的图片

    1、html

       <form class="container" enctype="multipart/form-data" method="post" id='formBox' name="form">
                <input type="file" id="chooseImage" name="file">
                <!-- 保存用户自定义的背景图片 -->
                <img id="cropedBigImg" value='custom' alt="lorem ipsum dolor sit" data-address='' title="自定义背景"/>
          </form>
    

    2、js

     $('#chooseImage').on('change',function(){
            var filePath = $(this).val();         //获取到input的value,里面是文件的路径
            var fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
            // 检查是否是图片
            if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
                error_prompt_alert('上传错误,文件格式必须为:png/jpg/jpeg');
                return;  
            }
            var src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
            $('#cropedBigImg').attr('src',src);
    });
    





    原文:https://blog.csdn.net/qq_29582277/article/details/83185363

  • 相关阅读:
    Unity3D AssetBundle相关
    [转]Unity3D新手引导开发手记
    努力多彩
    js sendBeacon
    js document.activeElement及使用
    js requestAnimationFrame
    js 1+'2' == '1'+'2'
    js scrollIntoViewIfNeeded
    汉字 3个字节
    js 浅拷贝和深拷贝
  • 原文地址:https://www.cnblogs.com/lxwphp/p/10897597.html
Copyright © 2011-2022 走看看