input file图片上传

前端之家收集整理的这篇文章主要介绍了input file图片上传前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="cnblogs_code">


    图片上传
    Box"
        Box-icon"
            
             
        
    
图片上传Box {:;:; }Box - icon {:;:;:;:; }Box - icon img {:;:; }Box - icon input {:;:;:;:;:; }{:;:;:;:;:;:;:;:; }{:;:;:; }{:;:;:;:;:;:; }{:;:;:;:;:;:;:; }
$scope.addPhoto = fileObj = file.files[0 formData = 'file' options =+ "/services/api/file/uploadImg"'POST''ticket' (rsp.code == 200= innerHtml = '
' + '
'".photo-Box""网络错误!"
attachmentArr =<span style="color: #0000ff">function<span style="color: #000000"> addPhoto(file) {
<span style="color: #0000ff">var fileObj = file.files[0<span style="color: #000000">];
<span style="color: #0000ff">var formData = <span style="color: #0000ff">new<span style="color: #000000"> FormData();
formData.append('file'<span style="color: #000000">,fileObj);
<span style="color: #0000ff">var options =<span style="color: #000000"> {
url: webroot + "/upload/uploadImg"<span style="color: #000000">,success: <span style="color: #0000ff">function<span style="color: #000000">(rsp) {
<span style="color: #0000ff">if (rsp.code == 200<span style="color: #000000">) {
imgs =<span style="color: #000000"> rsp.result;
<span style="color: #0000ff">var innerHtml = '<div class="photo-add" onmouSEOver ="IconShow(this)" onmouSEOut ="IconHide(this)">' +
'添加照片' +
'<div class="closeIcon">' +
'<span class="delPhoto-btn" onclick="delPhoto(this)">' + "X" +
'' +
'
' +
'
'<span style="color: #000000">;
$(".photo-Box"<span style="color: #000000">).before(innerHtml);
attachmentArr.push(rsp.result);
<span style="color: #008000">//<span style="color: #008000"> 超过两张图片隐藏图标
<span style="color: #008000">//<span style="color: #008000"> if (attachmentArr.length >= 2) {
<span style="color: #008000">//<span style="color: #008000"> $('.photo-Box-icon').hide();
<span style="color: #008000">//<span style="color: #008000"> };
} <span style="color: #0000ff">else<span style="color: #000000"> {
hint(rsp.message);
}
},error: <span style="color: #0000ff">function<span style="color: #000000">(e) {
console.log("网络错误!"<span style="color: #000000">);
}
};
$.ajax(options);
};
<span style="color: #008000">//<span style="color: #008000">删除图标显隐
<span style="color: #0000ff">function<span style="color: #000000"> IconShow(e) {
$(e).children('.closeIcon'<span style="color: #000000">).show();
};

<span style="color: #0000ff">function<span style="color: #000000"> IconHide(e) {
$(e).children('.closeIcon'<span style="color: #000000">).hide();
};
<span style="color: #008000">//<span style="color: #008000">图片删除
<span style="color: #0000ff">function<span style="color: #000000"> delPhoto(e) {
<span style="color: #0000ff">var thisImage = $(e).parent().parent().find('img').attr("src"<span style="color: #000000">);
attachmentArr.remove(thisImage);
$(e).parent().parent().remove();
};

原文链接:https://www.f2er.com/js/73975.html

猜你在找的JavaScript相关文章