var imgLoadIndex; //选择完事件 $(".fileInput").on("filebatchselected", function(event, files) { $(this).fileinput("upload");// 执行上传动作 }); // 文件移除事件 $('.fileInput').on('filecleared', function() { $("#" + this.id.replace("_file", "")).val(""); }); //上传中 $('.fileInput').on('filepreupload', function(event, data, previewId, index) { //上传中 imgLoadIndex = parent.layer.load(0, {shade : [ 0.3, '#808080']}); }) // 上传完成事件 $(".fileInput").on("fileuploaded",function(event, data, previewId, index) { parent.layer.close(imgLoadIndex); if (data.response.successful == true || data.response.successful == "true") { toastrSuccess("上传成功!"); var imgPath = data.response.data.url; var objId = this.id.replace("_file", ""); $("#" + objId).val(imgPath); $("#" + objId+"_img").css({ "background" : "url(" + restHost + imgPath + ") no-repeat", "background-size" : "100%" }); } else { if (data.response.msg != null && data.response.msg != "") { toastrError(data.response.msg); } } }); //上传完成事件 $(".fileInput").on('fileerror', function(event, data, msg) { //一个文件上传失败 parent.layer.close(imgLoadIndex); toastrError("上传异常,请重试!"); }) // 点击图片,模拟点击 input file $("#fileAutoUp").click(function () { $("#templateRar_file").click(); });