zoukankan      html  css  js  c++  java
  • 上传图片 点击按钮删除

    <!DOCTYPE html>
    <html>
    <head lang="zh-cn">
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no"/>

    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <title></title>
    <style>

    ul ,li{
    list-style: none;
    padding: 0;margin: 0;
    background-color: #fff;
    }
    p{
    margin: 0;
    padding: 0;
    }

    #box{
    100%;
    height: auto;
    }
    .img-d{
    margin-top: 30px;
    60px;
    height: 60px;
    text-align: center;
    position: relative;
    border: 1px solid #666666;
    display: inline-block;
    }
    .img-d span{
    display: inline-block;
    100%;
    height: 100% ;
    cursor: pointer;
    background: url(http://qqbxw.b0.upaiyun.com/static/imgs/jia_03.png) no-repeat 17px 17px ;
    }
    #up{
    display: none;
    }
    .tu{
    position: relative;
    display: inline-block;
    margin-right: 12px;
    }
    .tu2{
    display: inline-block;
    20px;
    height: 20px;
    font-size: 17px;
    position: absolute;
    top: -0px;
    right: -0px;
    color: #ffffff;
    text-align: center;
    line-height: 25px;
    cursor: pointer;
    background: url('timg.jpg') no-repeat;
    background-size: cover;
    border-radius: 50px;
    }
    </style>
    </head>
    <body>
    <div class="main">
    <ul id="box">
    <li class="img-d">
    <span class="up-s" ></span>
    <input type="file" id="up" multiple name="files">
    </li>
    </ul>
    </div>
    <div style="text-align: center; 100%;margin-top: 20%">
    <input type="submit" style="float: none; 70%;height: 40px;background-color: #FF7E00;color: #ffffff;border-radius: 5px;border: none;"/>
    </div>
    <script>

    // span的点击事件
    var addBtn = document.querySelector('.up-s');
    addBtn.addEventListener('click',function () {
    document.querySelector('#up').value = null;
    document.querySelector('#up').click();
    return false;
    },false);

    // 处理input点击之后的change事件
    document.getElementById("up").addEventListener("change",function(e){
    var files =this.files;
    var reader =new FileReader();
    reader.readAsDataURL(files[0]);
    reader.onload =function(e){
    var dx =(e.total/1024)/1024;
    if(dx>=2){
    alert("文件大小大于2M");
    return;
    }
    var result =this.result;//这里就是转化之后的DataURL
    $('.img-d').before("<div class='tu'><img src="+result+" class='tu1' width='60px' height='60px'><i class='tu2'></i><div>");
    //单选框--为谁买保险
    $(".tu2").click(function() {
    $(this).parent().remove();
    })
    };
    });
    </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    </body>
    </html>
  • 相关阅读:
    pip 最新版 发布(Python包安装和管理工具)
    Python使用cookie 免密登录了解一下
    夯实根基,必知必会的 Python 基础知识
    10个关于文件操作的小功能,都很实用~
    总结一些网站加密和混淆技术
    接口加密如何测试?
    艰难的这年,程序员的未来在哪里?
    警惕“职场PUA”!
    Python面试题及答案汇总
    Python实例练手项目汇总(附源码)
  • 原文地址:https://www.cnblogs.com/zcboy/p/6888072.html
Copyright © 2011-2022 走看看