$(document).ready(function () { $(document).off('click',sendFile).on('click','.upload-it',sendFile); $(document).off('click',selectFile).on('click','.select-file',selectFile); $(document).off('change',showMsg).on('change','.true-select',showMsg) }) function sendFile() { var fileData =new FormData(); var Url4='/student-upload-finished-product'; var file=$('#select')[0].files[0]; if($('.true-select').val()=='') { alert("请选择文件"); return; } alert(file); fileData.append("file",file); $.ajax({ type:"post", url:Url4, data:fileData, processData:false, contentType:false, success:function (data,status) { if(status=="success") { alert("上传成功"); } } }) } function selectFile() { $('.true-select').click(); } function showMsg() { var file=$(this).val(); var filename=getmsg(file); function getmsg(file) { var index=file.lastIndexOf("\\"); return file.substring(index+1); } $('.file-msg').css("opacity","1"); $('.file-name').html(filename); $('.file-msg').css("left","340px"); $('.file-input-frame').css("right","20px") $('.select-file').html("重新选择"); $('.select-file').css("background-color","#eb4548"); }