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

    //图片上传功能
    jQuery.fn.extend({
    uploadPreview: function (opts) {
    var _self = this,
    _this = $(this);
    opts = jQuery.extend({
    Img: "ImgPr",
    Width: 100,
    Height: 100,
    ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],
    Callback: function () {}
    }, opts || {});
    _self.getObjectURL = function (file) {
    var url = null;
    if (window.createObjectURL != undefined) {
    url = window.createObjectURL(file)
    } else if (window.URL != undefined) {
    url = window.URL.createObjectURL(file)
    } else if (window.webkitURL != undefined) {
    url = window.webkitURL.createObjectURL(file)
    }
    return url
    };
    _this.change(function () {
    if (this.value) {
    if (!RegExp(".(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
    alert("选择文件错误,图片类型必须是" + opts.ImgType.join(",") + "中的一种");
    this.value = "";
    return false
    }
    if ($.browser.msie) {
    try {
    $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
    } catch (e) {
    var src = "";
    var obj = $("#" + opts.Img);
    var div = obj.parent("div")[0];
    _self.select();
    if (top != self) {
    window.parent.document.body.focus()
    } else {
    _self.blur()
    }
    src = document.selection.createRange().text;
    document.selection.empty();
    obj.hide();
    obj.parent("div").css({
    'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',
    'width': opts.Width + 'px',
    'height': opts.Height + 'px'
    });
    div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src
    }
    } else {
    $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
    }
    opts.Callback()
    }
    })
    }
    });


    //上传图片
    $("#doc").uploadPreview({ Img: "preview"});//上传图片
  • 相关阅读:
    pytorch报错:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
    python运行报错:cannot import name 'InteractiveConsole'
    sudo pip3找不到命令
    pytorch入门1——简单的网络搭建
    caffe训练时报错
    python滴啊用caffe时的小坑
    求两个字符串的编辑距离
    归并排序
    复杂度n求数组的第K大值
    牛顿法与拟牛顿法学习笔记(一)牛顿法
  • 原文地址:https://www.cnblogs.com/asylm/p/8473337.html
Copyright © 2011-2022 走看看