zoukankan      html  css  js  c++  java
  • 图片上传js

    var imgURL;
    function getImgURL(node) {
    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{
    //Firefox7.0
    imgURL = file.getAsDataURL();
    //alert("//Firefox7.0"+imgUrl);
    }catch(e){
    //Firefox8.0以上
    imgURL = window.URL.createObjectURL(file);
    //alert("//Firefox8.0以上"+imgUrl);
    }
    }catch(e){ //这里不知道怎么处理了,如果是遨游的话会报这个异常
    //支持html5的浏览器,比如高版本的firefox、chrome、ie10
    if (node.files && node.files[0]) {
    var reader = new FileReader();
    reader.onload = function (e) {
    imgURL = e.target.result;
    };
    reader.readAsDataURL(node.files[0]);
    }
    }
    if(imgURL!='' || imgURL!=undefied){
    $('.addImg').html('已上传');
    }
    creatImg(imgURL);
    return imgURL;
    }

    function creatImg(imgUrl){ //根据指定URL创建一个Img对象
    var textHtml = "<img src='"+imgUrl+"'/>";
    $(".ImgGive").html(textHtml);
    }

    <input type="file" name="donee_img" onchange="getImgURL(this)" accept="image/*" placeholder="添加图片" class="rightInput opacity donee_img" >

    对呀phone6 input加了capture="camera" 6只会调起相机 不会调起相册

  • 相关阅读:
    ASP.NET
    jquery
    rowcommand事件中获取控件
    Net 自定义Excel模板导出数据
    代码阅读方法与实践---阅读笔记06
    代码阅读方法与实践---阅读笔记05
    代码阅读方法与实践---阅读笔记04
    软件需求十步走---阅读笔记03
    软件需求十步走---阅读笔记02
    软件需求十步走---阅读笔记01
  • 原文地址:https://www.cnblogs.com/tanks/p/7462924.html
Copyright © 2011-2022 走看看