• input type=file实现图片上传


    <label for="file">
        <img src="images/morende.jpg" alt="">
        <span>点击更换头像</span>
    </label> <input type="file" name="file" id="file" accept="image/*" value="" hidden=""/>
    $("input[type='file']").change( function(event) {//上传图片
      console.log(event)
    var file = event.currentTarget.files[0] var formFile = new FormData(); formFile.append("file", file); $.ajax({ url: ajaxURL+'/currency/istImage', type: 'POST', data: formFile, async: true, cache: false, contentType: false, processData: false, dataType:'json', success: function(res) { console.log(res); } }) });

    或者循环多个上传

    <input type="file" onchange="upload(this)">
    <script>
    function upload(obj){
    var files = obj.files ;
    var formData = new FormData();
    for(var i = 0;i<files.length;i++){ 
    formData.append("upfile[]", files[i]);
    
    }
    $.ajax({
    url: "1.php",
    type: "POST",
    data:formData,
    cache:false, //不设置缓存
    processData: false, // 不处理数据
    contentType: false // 不设置内容类型
    }); 
    }

    </script>

  • 相关阅读:
    Codeforces Round #629 (Div. 3) (A ~ F)
    st表
    Educational Codeforces Round 81 (Rated for Div. 2)
    hihocoder#1996 : 01匹配
    P2056 [ZJOI2007]捉迷藏
    P2495 [SDOI2011]消耗战
    GUETOJ1335
    优先队列重载比较运算
    CCF认证201909-4 推荐系统
    P3178 [HAOI2015]树上操作
  • 原文地址:https://www.cnblogs.com/li-sir/p/12072965.html
Copyright © 2020-2023  润新知