//个人动态图片 上传
$("#dynamic").change(function () {
let file = $(this).get(0).files[0];
// console.log(file);
if (file.type == 'image/png' || file.type == 'image/jpeg') {
var fileType = console.log(file.type);
let reader = new FileReader();
reader.readAsDataURL(file);
//清除 val
$("#dynamic").val('');
reader.onloadend = function (e) {
console.log(e.target);
$.ajax({
type: "POST",
url: "/index/user/uploaduserimg",
data: {"content": e.target.result,"fileType":fileType},
dataType: "JSON",
success: (res) => {
if (res.status == 2) {
hintoperation(res.msg, '/static/webpctwo/image/success.png');
} else {
hintoperation(res.msg, '/static/webpctwo/image/fail.png');
}
},
error: (res) => {
hintoperation(res.msg, '/static/webpctwo/image/fail.png');
}
});
let newimg = `<img src="${reader.result}" alt="">`;
$('.newdynamic').append(newimg);
}
} else {
//提示类型不符
hintoperation('请上传 png/jpg 格式', '/static/webpctwo/image/fail.png');
}
});
**获取input 获取 文件信息 类型判断 onloadend 上传 base64 文件 **
最后
以上就是体贴大碗最近收集整理的关于js input 上传 图片的全部内容,更多相关js内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复