版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014074697/article/details/79354318
---css---
<form id="uploadForm" method="post" action="../userSelfSer/insertUploadFile.action" enctype="multipart/form-data">
<table>
<tr>
<td id="photo" style="padding-left:10px;">
<input name="uploadFile" id="uploadFile" class="easyui-filebox" labelPosition="top" data-options="buttonAlign:'left',buttonText: ' 浏 览 <i class=\'icon-search\'> </i>',prompt:'请选择待上传文件...'" style="width:300px;"></td>
<td style="padding:10px;" >
<a class="btn btn-mini btn-info" href="javascript:okUpload();" id="btnOK">上 传 </a>
</td>
</tr>
</table>
</form>
---js----
/**附件上传*/
function okUpload(){
if(editId==undefined){
var epath = $('#uploadFile').filebox('getValue');
if(isNotEmpty(epath)){
var len=epath.split("\\").length;
var fileName=epath.split("\\")[len-1];
upload(0,fileName);
}
}
else{
upload(editId,null);
}
}
function upload(ownerId,fileName){
var formData = new FormData($("#uploadForm" )[0]);
$.ajax({
type: "POST",
url: contextPath+"/incMng/insertUploadFile.action?ownerId="+ownerId,
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (res) {
if(res.successed){
if(ownerId==0){
//此处附件已经插入到附件表,但工单尚未保存,所以二者未做关联,不可直接查询所有附件进行展示
var attchHtml="<a style='color:blue;cursor:pointer;display:block;' href='"+res.attch.downloadUrl+"' target='blank;'>"+fileName+"</a>";
$("#fileList").append(attchHtml);
attchIds+=(attchIds==""?res.attch.id:(","+res.attch.id));
}
else{
$("#fileList").html(res.fileList);
}
$("#uploadFile").filebox('clear');
}else{
$.messager.alert("提示信息","上传失败!","error");
}
},
error: function (data) {
$.messager.alert("提示信息","上传失败!","error");
},
beforeSend: function () {
$.myloading({title: "正在上传,请稍后..."});
},
complete: function () {
$.myloading("hide");
}
});
}