zoukankan      html  css  js  c++  java
  • 图片上传(1)

    html部分

    <form id= "uploadForm">
    <input type ="file" name="file" class="fileContent hiddenClass" onchange="doUpload()" hidden/>
    <input type ="text" name="areaCode" class="hiddenClass" value="globalservice" hidden/>
    <input type ="text" name="sessionId" class="hiddenClass" value="22522BCF22D9A978AA6577342134F2A4" hidden/>
    </form>
    <button class="btn zbtn-bg btn-sm" onclick="triggerUpLoad()">上传附件</button>
    <div class="picFile">
    <ul id="picContent">
    </ul>
    </div>

     

    css部分

    .picContent li{
    list-style: none;
    margin: 2px;
    500px;float:
    left;border: 1px solid #78BC27;
    position: relative
    }
    span.fileNameClass{
    position: relative;
    top:-50px;
    left:86px;
    380px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    -o-text-overflow: ellipsis;
    display:block;
    }
    span.removeImg{
    position: absolute;
    top:0px;
    right:6px;
    cursor: pointer;
    }
    .enlargePic{
    position: fixed;z-index: 9999;display: none;
    }

    js 部分

    function doUpload() {
    var commonUrl='http://192.168.12.200:8181';
    var fileName=$(".fileContent")[0].files[0];
    if(!fileName){
    return false;
    }
    var formData = new FormData($( "#uploadForm" )[0]);
    $.ajax({
    url: commonUrl+'/file/upload' ,
    type: 'POST',
    data: formData,
    async: false,
    cache: false,
    contentType: false,
    processData: false,
    success: function (data) {
    if(data.payload.results.file.fileName){
    var file=data.payload.results.file;
    console.log(data);
    var imgUrl=commonUrl+'/file/'+file.url;
    console.log(imgUrl);
    var imgShow='<li style="500px;float: left;border: 1px solid #CCCCCC;position: relative"><div style="height: 90px;padding: 4px;overflow: hidden" class="imgContent"><a href="'+imgUrl+'" target="_blank"><img src="'+imgUrl+'" style="80px;height: 80px"/></a><span class="fileNameClass">'+file.fileName+'</span><span onclick="removeImg(this)" class="removeImg">&times;</span></div></li>';
    $('#picContent').append(imgShow);
    }
    },
    error: function (data) {

    }
    });
    }
    function removeImg(obj) {
    $(obj).parent('div').parent('li').remove();
    }
    function triggerUpLoad() {
    $('.fileContent').trigger('click');
    }
  • 相关阅读:
    纯JS制作选项卡--JavaScript实例集锦(初学)
    超级简单实用的CSS3动画,增添网页效果
    3种方法实现图片瀑布流的效果(纯JS,Jquery,CSS)
    CSS动画小结
    遗忘比死亡更可怕
    matplotlib笔记2
    matplotlib笔记1
    pandas数据结构之Panel笔记
    pandas数据结构之Series笔记
    ndarray笔记续
  • 原文地址:https://www.cnblogs.com/cx709452428/p/7894861.html
Copyright © 2011-2022 走看看