首页 技术 正文
技术 2022年11月21日
0 收藏 752 点赞 4,211 浏览 1223 个字
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Js实现文件上传功能</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<style>
.a-upload {
position: relative;
display: inline-block;
background: #D0EEFF;
border: 1px solid #99D3F5;
border-radius: 4px;
padding: 4px 12px;
overflow: hidden;
color: #1E88C7;
text-decoration: none;
text-indent: 0;
line-height: 20px;
}
.a-upload input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
}
.a-upload:hover {
background: #AADFFD;
border-color: #78C3F3;
color: #004974;
text-decoration: none;
}
</style>
</head>
<body>
<form method="post"
enctype="multipart/form-data"
id="upload">
<a href="javascript:;" rel="external nofollow" id="pic" class="a-upload">
<input type="file"
name="file"
>
点击这里上传文件
</a>
<input type="button" value="提交" onclick="uploadPic()">
<span class="showUrl"></span>
<img src="" alt="" class="showPic">
</form>
</body>
<script>
function uploadPic() {
var form = document.getElementById('upload')
var formData = new FormData(form);
$.ajax({
url:"https://sscpre.boe.com/v1/medical-console/medical/file/upload",
type:'post',
data:formData,
processData:false,
success:function (res) {
if(res){
alert('上传成功')
}
$('#pic').val('');
$(".showUrl").html(res);
$(".showPic").attr("src",res);
},
error:function(err){
alert('网络失败,请稍后再试',err)
}
})
}
</script>
</html>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898