http://www.sojson.com/blog/214.html
//触发的id
var ids = new Array("pickfiles1","pickfiles2","pickfiles3","pickfiles4");
$.each(ids,function(i,n){
var self = this.toString();
//实例化一个plupload上传对象
var uploader = new plupload.Uploader({
browse_button : self, //触发文件选择对话框的按钮,为那个元素id
url : 'index.php' ,//服务器端的上传页面地址
max_file_size: '2mb',//限制为2MB
filters: [{title: "Image files",extensions: "jpg,gif,png"}]//图片限制
});
//在实例对象上调用init()方法进行初始化
uploader.init();
//绑定各种事件,并在事件监听函数中做你想做的事
uploader.bind('FilesAdded',function(uploader,files){
uploader.start();
});
uploader.bind('FileUploaded',function(uploader,files,data){
var imgUrl = "//cdn.www.sojson.com/";
//这里得到图片的id
var id = self.search("-img") == -1?self +"-img":self;
console.log("现在在上传的身份证是:",self.search('cardzmbtn')==0?'正':'反',"面");
//成功判断
if(data.status == 200){
data = $.parseJSON(data.response);
var imagePath = imgUrl + data.file;
document.getElementById(id).src = imagePath;
if(self.search('cardzmbtn')==0){
$("#cardzmbtn-input").val(imagePath).attr('src-data',data.file);
}else
{
$("#cardbmbtn-input").val(imagePath).attr('src-data',data.file);
}
}
});
});