zoukankan      html  css  js  c++  java
  • html上传文件和图片

    上传文件:<input type="file" id="file" />

    上传文件优化样式

    Html

    <p class="liuyanfile">

    <label>上传文件</label>

    <a href="#" class="file">选择文件<input type="file" id="file" /></a>

    <span>未选择任何文件</span>

    </p>

    Css

    .file {

        position: relative;

        display: inline-block;

        overflow: hidden;

        text-indent: 0;

        line-height: 35px;

    text-align: center;

    101px;

    height: 35px;

    background-image:

    linear-gradient(0deg, #e4e4e4 0%, #e6e6e6 39%, #f2f2f2 100%, #797979 100%, #000000 100%),

    linear-gradient(#dddddd, #dddddd);

    background-blend-mode: normal,normal;

    border-radius: 2px;

    border: solid 1px #cccccc;

    vertical-align: middle;

    margin-left: 45px;

    }

    .file:hover{

    color: #010101;

    }

    .addliuyan .liuyanfile span{

    color: #666666;

    margin-left: 20px;

    }

    .file input {

        position: absolute;

        font-size: 100px;

        right: 0;

        top: 0;

        opacity: 0;

    }

    上传图片优化样式

    Html:

    <div class="sh userpic">

    <div class="img left">

    <img src="img/fixed/userpic.jpg" >

    </div>

    <a class="left" href="javascript:;">编辑头像

    <input type="file" name="" id="picfile" value="" />

    </a>

    </div>

    Js

    // 上传图片

    $("#picfile").change(function(){

    var filePath = $(this).val();

    let fr = new FileReader(); //创建new FileReader()对象

    let imgObj = this.files[0];//获取图片

    fr.readAsDataURL(imgObj);//将图片读取为DataURL

    if(filePath.indexOf("jpg") != -1 || filePath.indexOf("JPG") != -1 || filePath.indexOf("PNG") != -1 || filePath.indexOf("png") != -1){

    fr.onload = function() {

    $(".setselfmsg .userpic img").attr("src",this.result);

    }

    } else {

    confirm("您未上传文件,或者您上传文件类型有误!");

    return false;

    }

    })

    Css:

    .setselfmsg .userpic a{

    display: block;

    overflow: hidden;

    position: relative;

    }

    .setselfmsg #picfile{

    position: absolute;

    left: 0;

    top:0;

    opacity: 0;

    font-size: 100px;

    }

  • 相关阅读:
    Scraping JavaScript webpages with webkit | WebScraping.com
    linux命令行抓取网页快照-(xvfb+CutyCapt)
    Xvfb+YSlow+ShowSlow搭建前端性能测试框架
    Lind.DDD.Paging分页模块介绍
    Lind.DDD.IoC依赖注入与面向方面的实现
    Lind.DDD.Caching分布式数据集缓存介绍
    Lind.DDD.Events领域事件介绍
    知方可补不足~sqlserver中的几把锁~续
    BUG: scheduling while atomic: events/0/4/总结
    真正理解javascript的五道题目.
  • 原文地址:https://www.cnblogs.com/xuwenqin/p/14133989.html
Copyright © 2011-2022 走看看