Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

文件上传weui-uploader js显示已选择图片方法 #439

Open
wants to merge 61 commits into
base: master
Choose a base branch
from

Conversation

wuyuande
Copy link

@wuyuande wuyuande commented Sep 11, 2017

weui-uploader JS部分的代码,由于当前的jquery-weui没有实现已选图片显示的方法,所以在weui.io微信官方的weui.js中借鉴了关于显示的JS代码,并做了修改,增加了显示已上传图片数
html端如下:

<div class="weui-cell"> <div class="weui-cell__bd"> <div class="weui-uploader"> <div class="weui-uploader__hd"> <p class="weui-uploader__title">图片上传</p> <div class="weui-uploader__info" id="uploaderCount" value="0">0/3</div> </div> <div class="weui-uploader__bd"> <ul class="weui-uploader__files" id="uploaderFiles"> </ul> <div class="weui-uploader__input-box"> <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple=""> </div> </div> </div> </div> </div>

JS代码部分:
`
/======================================================
************ weui-uploader 上传方法 ************
======================================================
/
$(function () {
var tmpl = '

  • ',
    $gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
    $uploaderInput = $("#uploaderInput"),
    $uploaderFiles = $("#uploaderFiles"),
    $uploaderCount = $("#uploaderCount")
    ;

    $uploaderInput.on("change", function (e) {
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        var count =parseInt($uploaderCount.attr("value"));
        for (var i = 0, len = files.length; i < len; ++i) {
            var file = files[i];
    
            if (url) {
                src = url.createObjectURL(file);
            } else {
                src = e.target.result;
            }
            count = count + 1;
            //$uploaderFiles.append($(tmpl.replace('#url#', src)));
            $uploaderFiles.append($(tmpl.replace('#url#', src).replace('#imgid#', "img" + count).replace('#url#', src)));
        }
        $uploaderCount.attr("value", count);
        $uploaderCount.html(""+count+"/3");
    });
    $uploaderFiles.on("click", "li", function () {
        $galleryImg.attr("style", this.getAttribute("style"));
        $gallery.fadeIn(100);
    });
    $gallery.on("click", function () {
        $gallery.fadeOut(100);
    });
    

    });
    `

    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants