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();
    }
    });
    });

  • 相关阅读:
    ide 安装eval reset插件 Pycharm 永久破解
    Centos7.9安装RabbitMQ
    Linux环境下安装Centos7.9时没有图形界面的解决办法
    JS,对部分值base64解码
    consul 配置备份
    AutoMapper后遇到的“Missing map”与“Missing type map configuration”问题
    osg绘制圆柱体
    IfcFlowMovingDevice
    opencv absdiff
    IfcFlowMovingDeviceType
  • 原文地址:https://www.cnblogs.com/weiwentaweb/p/7519977.html
Copyright © 2011-2022 走看看