代码归档
<!-- 上传 -->
<div class="form-horizontal" id="saForm">
<div class="col-md-10 input-group">
<input id="sa-upload" type="file" style="display:none">
<input id="saCover" class="form-control" type="text">
<span onclick="$('input[id=sa-upload]').click();"
style="cursor: pointer;" id="sa-span">
<button class="btn btn-primary">上传文件</button>
</span>
</div>
</div>
<!-- end -->
<script>
// 上传SA
function uploadSa() {
$("#sa-upload").on("change", function(event){
var formData = new FormData();
var fileObj = event.target.files[0];
var fileName = fileObj.name;
formData.append("file", fileObj);// 文件对象
$.ajax({
url: apiUrl + "ynqd/file/uploadbill",
type: 'POST',
cache: false,
data: formData,
processData: false,
contentType: false,
dataType:"json",
beforeSend: function(){
$("#saCover").val(fileName).attr("disabled",true);
$("#sa-span").attr("onclick","");
$("#sa-span").find("button").removeClass('btn-primary')
return;
},
success : function(res) {
console.log("uploadSa=>",res)
if(res.status) {
$("#saCover").val("").attr("disabled",false);
$("#sa-span").attr("onclick","$('input[id=sa-upload]').click();");
$("#sa-span").find("button").addClass('btn-primary')
alert("上传成功");
}else{
alert(res.msg);
}
}
});
});
}
</script>