zoukankan      html  css  js  c++  java
  • 自定义input上传图片框

    ro1YfU.png

    <!-- 自定义按钮效果 -->
                    <div class="input_img_father_div">
                        <input class="upload_input" id="result_background"  name="result_background"  type="file"  />
                        <div class="input_img_btn_div">
                            <c:if test="${empty result.result_background}"> <span class="input_img_btn_span">上传图片:</span></c:if>
                            <img id="img_result_background" class="upload" style=" 80px; height:80px;"  src="${result.result_background}" />
                        </div>
                    </div>
                    <!-- 自定义按钮效果 -->
    
    // {# 上传样板图片预览 #}
        $(".upload_input").change(function () {
            var objUrl = getObjectURL(this.files[0]);//获取文件信息
            console.log(objUrl)
            if (objUrl) {
                $(this).parent().find('span.input_img_btn_span').hide();
                $(this).parent().find('img.upload').show();
                $(this).parent().find("img.upload").attr("src", objUrl);
            }
        });
        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL != undefined) {
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }
    
    /****上传图片****/
    .input_img_father_div {
        position: relative;
         80px;
        height: 80px;
        vertical-align: middle;
        opacity: 60;
        background-color: #c6c6c6;
        display: flex; /*flex弹性布局*/
        justify-content: center;
        align-items: center;
        margin-left: 137px;
    }
    .upload_input {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        opacity: 0;
         80px;
        height: 80px;
    }
    
    .input_img_btn_div {
        text-align: center;
        display: flex;
        flex-direction: column; /*元素的排列方向为垂直*/
        justify-content: center; /*水平居中对齐*/
        align-items: center; /*垂直居中对齐*/
    }
    
    .input_img_btn_span {
        font-size: 16px;
        vertical-align: middle;
    }
    img.upload {
         80px;
        height: 80px;
    }
    /****上传图片****/
    
  • 相关阅读:
    nginx 启用php解析及解决无法访问报错Primary script unknown的过程
    百度云服务器连接码云的坑
    async函数测试
    centos6.8安装mysql5.7及用navicat远程连接
    JavaScript模块知识理解
    为什么if else 语句里不能用函数声明定义函数,而可以用函数表达式定义函数
    Java8-对map过滤
    git cherry-pick 的使用
    Java8-对map排序
    Java8过滤器(Filter)
  • 原文地址:https://www.cnblogs.com/SimonHu1993/p/14200367.html
Copyright © 2011-2022 走看看