首页 / JQUERY / 原生js图片上传 jquery
原生js图片上传 jquery
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了原生js图片上传 jquery,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1742字,纯文字阅读大概需要3分钟。
内容图文
![原生js图片上传 jquery](/upload/InfoBanner/zyjiaocheng/1036/31012025bea34f6ba75eacb144177662.jpg)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="divport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>测试</title>
<style type="text/css">
.userInfo{
margin-top: 52px;
width: 94%;
margin-left: 3%;
background-color: white;
border-radius: 12px;
display: flex;
flex-direction: column;
}
.userHeader{
position: relative;
}
.row{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding:10px 20px 10px 12px;
font-size: 30px;
border-bottom: solid 1px #E9E9E9;
}
.row:last-child{
border-bottom:none
}
.userHead{
width: 100px;
height: 100px;
border-radius: 100%;
}
</style>
</head>
<body ontouchstart>
<div class="userInfo">
<div class="userHeader row">
<span>头像</span>
<img class="userHead" src="C:\Users\Administrator\Pictures\Screenshots\cat.jpg" alt="" />
<input type="file" value="" id="chooseFile" multiple="multiple" accept="image/*" style="display: none ;" onclick="toUploadPic(this);"/>
</div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
var HTTP="http://test.shirenzuile.com/yslp-agent/";
$('.userHead').click(function(){
$("#chooseFile").trigger("click");
});
function toUploadPic(dom){
console.log(dom.value,"dom")
if(dom.value.length != 0){
if(!/image\/\w+/.test(dom.files[0].type)){
pointOut("请确保文件为图像类型");
return false;
}
var formData = new FormData();
formData.append("file", dom.files[0]);
$.ajax({
type:"post",
url:HTTP+"file/upload",
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
dataType: "json",
success:function(data){
console.log(data,11111);
if(data.result==0){
$(".userHead").attr("src",data.data);
}
}
});
}
}
</script>
内容总结
以上是互联网集市为您收集整理的原生js图片上传 jquery全部内容,希望文章能够帮你解决原生js图片上传 jquery所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。