当按钮是一个图片的时候,在ie下的样式修改div.moxie-shim-html4{ filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); opacity:0; width:88px; height:43px;}
var uploader = new plupload.Uploader({ browse_button:"id", /*触发按钮id, 此处也可以是一个选择器*/ url:' ', /*上传路径*/ filters:{ /*设置上传文件*/ mime_type:[ {title:"网页文件",extensions:"htm,html"} ] }});uploader.bind('FilesAdded',function(uploader,files) { /*选择文件后触发*/ uploader.start(); /*开始上传*/});uploader.bind('FileUploaded',function(uploader,file,d){ /*当文件添加到上传队列后触发*/ var data = $.parseJSON(d.response); if(data.success){ /*判断是否成功*/ alert("成功") }else{ alert("失败") }})uploader.init(); /*初始化*/
当选中文件即上传时,在FilesAdded方法中加入 uploader.start()方法(开始上传文件方法);
多个上传按钮
var ele = [];$("div").find("a").each(function(){ ele.push($(this)[0]);});$.each(ele,function(){ var self = this; var uploader = new plupload.Uploader({ browse_button:self, /*触发按钮id, 此处也可以是一个选择器*/ url:' ', /*上传路径*/ filters:{ /*设置上传文件*/ mime_type:[ {title:"网页文件",extensions:"htm,html"} ] }});})
下载
location.href= 'url'
formData上传图片
AsDataURL(e,i) { //图片上传 var _this = this; var index = +$(e.target).attr("data-index"); //索引 var _i = i; if(_this.pageData.studentList[index].efilePhoto == null || _this.pageData.studentList[index].efilePhoto == undefined){ _this.pageData.studentList[index].efilePhoto = []; } var file = $(e.target)[0].files; //获取上传文件 if (_this.pageData.studentList[index].efilePhoto == null || _this.pageData.studentList[index].efilePhoto == undefined) { //定义原有回显img的长度 var imgLen = 0; } else { var imgLen = _this.pageData.studentList[index].efilePhoto.length; } if ((file.length + imgLen) > 4) { return showAlertInfo("fail", "最多只能选择4张图片!"); } else { var formData = new FormData(); for (i = 0; i < file.length; i++) { // 验证图片格式和大小 if ((file[i].type).split("/")[0] !== "image") { return showAlertInfo("fail", "您上传的文件不是图片格式的!"); } if (file[i].size > 10485760) { return showAlertInfo("fail", "图片大小不能大于10M!"); } formData.append("fileImage", file[i]); }; var studentCode = _this.pageData.studentList[index].studentCode; formData.append("itemCode", getUrlParam("itemCode")); formData.append("studentCode", studentCode); $.ajax({ url: ctx + '/classFeedBack/pushClassroomFeedbackCtrl/uploadImageServe.do', type: 'post', data: formData, async: false, cache: false, contentType: false, processData: false, beforeSend: function () { showLoading(); }, complete: function () { closeLoading(); }, success: function (msg) { if (msg.result == 1) { for (var j=0;j{ value.efilePhoto.map((val,i)=>{ b.push(val.imageName); }) }); _this.form.studentList[_i].photoName = b; } else { showAlertInfo("fail", msg.message); } } }); } }