• 点击之后上传图片到页面 input type="file" 样式



    <!DOCTYPE html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test js</title>
    <style>
    #pic{
    100px;
    height:100px;
    border-radius:50% ;
    margin:20px auto;
    cursor: pointer;
    }
    .upfile{
    /*opacity: 0;*/
    }
    .file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
    }
    .file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
    }
    .file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
    }

    </style>
    </head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>


    <body>

    <div class="img_show img_show1">
    <p class="p-flex">
    <span class="vertical-blue"></span><span class="left-A" >水印设置</span>
    <img src="" alt="" class="img-big" width="103" height="103">
    <img src="" alt="" class="img-centre" width="103" height="103">
    <img src="" alt="" class="img-small" width="103" height="103" >
    </p>
    <p class="text-blue">
    <a href="javascript:;" class="file">上传水印
    <input type="file" class="upfile" value="更换" class="changes" accept="image/*">
    </a>
    </p>
    </div>

    </body>
    <script>
    upfile = function(){
    $('.img_show').each(function(){
    var $this = $(this),
    btn = $this.find('.upfile'),
    img = $this.find('img');
    btn.on('change',function(){
    var file = $(this)[0].files[0],
    imgSrc = $(this)[0].value,
    url = URL.createObjectURL(file);
    if (!/.(jpg|jpeg|png|JPG|PNG|JPEG)$/.test(imgSrc)){
    alert("请上传jpg或png格式的图片!");
    return false;
    }else{
    img.attr('src',url);
    img.css({'opacity':'1'});
    }
    });
    });
    }();
    </script>
    </html>

  • 相关阅读:
    简单易懂dubbo入门实例
    Java中String和byte[]间的 转换
    优秀项目
    Linux下命令行安装weblogic10.3.6
    Linux中VMware虚拟机增加磁盘空间的扩容操作
    office2016_windows永久激活查看方法
    解决eclipse报PermGen space异常的问题
    Ubuntu 18.04上nginx+php环境搭建
    git hook之commit-msg用于检测提交时间是否正确
    maven随记
  • 原文地址:https://www.cnblogs.com/zouyun/p/7944241.html
Copyright © 2020-2023  润新知