zoukankan      html  css  js  c++  java
  • 微信web开发的上传图片js接口

    $('.chooseImage').click(function(){
                wx.chooseImage({
                    count: pic_num, // 默认9,大于9也是显示9
                    sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 'original', 
                    success: function (res) {
                        images.localId = res.localIds;
                        alert('已选择 ' + res.localIds.length + ' 张图片');
                        var img_data = "";
                        $.each(images.localId, function(i, v)
                        {
                            img_data += "<img class='wimg-item' src='"+v+"'>";
                        });
                        $("#image_content .chooseImage").before(img_data);
                        $("#uploadImage").click();
                    }
                });
            });
    
    
            document.querySelector('#uploadImage').onclick = function () {
                if (images.localId.length == 0) {
                    alert('请先使用 chooseImage 接口选择图片');
                    return;
                }
                var i = 0, length = images.localId.length;
                images.serverId = images.serverId || [];
                function upload() {
                    wx.uploadImage({
                        localId: images.localId[i],
                        isShowProgressTips: i == 0 ? 1:0,// 第一张图显示进度,避免出现一会弹出一个进度等待
                        success: function (res) {
                            i++;
                            $('#ask_submit').html('正在上传 '+i+'/'+length);
                            if(i>=length)
                            {
                                $('#ask_submit').html('确定');
                                // alert('已上传:' + i + '/' + length);
                            }
    
                            images.serverId.push(res.serverId);
                            if (i < length && i <= pic_num) {
                                upload();
                            }
                        },
                        fail: function (res) {
                            alert('~><~ 图片上传失败,请稍后再试...');
                            //alert(JSON.stringify(res));
                        }
                    });
                }
                upload();
            };
        });
  • 相关阅读:
    255以内全一的二进制数
    XP下ubuntu双系统安装方法
    数据库的增删改查
    网安团队建设
    链表相关操作
    操作系统及其他----面试
    排序算法之----快速排序
    排序算法之----希尔排序
    排序算法之----选择排序&插入排序
    排序算法之----冒泡排序
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4886132.html
Copyright © 2011-2022 走看看