zoukankan      html  css  js  c++  java
  • 上传头像

    <div class="commodityImg_evaluate">
    <div class="ge_pic_icon_Infor">
    <img onclick="getElementById('file').click()" title="点击添加图片" alt="点击添加图片" src="images/tianjia.png">
    </div>
    <div class="Infor_file">
    <input type="file" multiple="multiple" id="file" name='img' style="height:0;0;z-index: -1; position: absolute;" onchange="getPhoto(this)"/>
    </div>
    </div>

    // 调用相册
    function getPhoto(node) {
    var imgURL = "";
    try{
    var file = null;
    if(node.files && node.files[0] ){
    file = node.files[0];
    }else if(node.files && node.files.item(0)) {
    file = node.files.item(0);
    }
    //Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
    try{
    imgURL = file.getAsDataURL();
    }catch(e){
    imgRUL = window.URL.createObjectURL(file);
    }
    }catch(e){
    if (node.files && node.files[0]) {
    var reader = new FileReader();
    reader.onload = function (e) {
    imgURL = e.target.result;
    };
    reader.readAsDataURL(node.files[0]);
    }
    }
    creatImg(imgRUL);
    return imgURL;
    }
    function creatImg(imgRUL){
    var textHtml = "<img src='"+imgRUL+"'/>";
    $(".myNews_Headportrait").html(textHtml);
    //uoloadImg();
    //console.log(imgRUL)
    }
    // 上传图片
    $("#file").change(function(){
    //创建FormData对象
    var dataImg = new FormData();
    //为FormData对象添加数据
    $.each($('#file')[0].files, function(i, file) {
    dataImg.append('img', file);
    });
    $.ajax({
    url:''+url+'/appupload/upload',
    type:'POST',
    data:dataImg,
    cache: false,
    contentType: false, //不可缺
    processData: false, //不可缺
    success:function(data){
    console.log(data);
    //data = $(data).html();
    }
    });
    });

  • 相关阅读:
    在ConcurrentModificationException异常上的联想
    记录一下自己爬虎牙LOL主播的爬虫思路
    ajax解决跨域问题
    解决多线程下数据库操作问题
    浅谈时间复杂度
    想一下,最大公约数怎么求
    IO流与IO缓冲
    循环移位
    3Sum探讨(Java)
    Two Sum(两个数的相加)
  • 原文地址:https://www.cnblogs.com/weiwentaweb/p/7519977.html
Copyright © 2011-2022 走看看