• js 图片上传(iframe)


    //上传图片构造函数
    function FileUploader(targetId, uploadInputId, uploadFormId, picAreaId, delUrl, targetInput, fileName) {
    this.targetId = targetId;
    this.uploadInputId = uploadInputId;
    this.uploadFormId = uploadFormId;
    this.picAreaId = picAreaId;
    this.delUrl = delUrl;
    this.targetInput = targetInput;
    this.iframeName = undefined; //当前iframe的名字
    this.fileName = fileName; //当前iframe的名字

    return {
    upload: this.upload,
    apendPic: this.apendPick
    };
    };


    //开始上传 FileUploader.prototype.upload = function () { $('#' + this.targetId).click(function () { $('#' + this.uploadInputId).click(); }); }; //添加图片 FileUploader.prototype.appendPic = function () { var fileId = this.fileName.substring(0, this.fileName.indexOf('.')); var picHtml = '<div id="' + fileId + 'div" style="float: left; margin-left: 5px; position: relative"><a id="' + fileId + 'del" style="height: 20px; 20px; position: absolute; top: -2px; right: -5px; z-index: 10;" class="panel-tool-close" /><img id="' + fileId + '" style="border: 10px solid #ddd; padding: 5px; 100px; height: 80px;" src="../content/FileUploaders/' + this.fileName + '" /></div>'; $('#' + this.picAreaId).append(picHtml); //绑定删除事件 $('#' + fileId + 'del').click(function () { this.delPic(); }); //绑定图片点击事件 $('#' + fileId).click(function () { window.open('/picupload/picview?imgname=' + fileName); }); //添加图片名到input $('#' + targetInput).val($('#' + targetInput).val() + ',' + fileName); }; //删除图片 FileUploader.prototype.delPic = function () { $.post(this.delUrl, { imgname: this.fileName }, function (data) { //提示 if (data.msg.toLowerCase() == 'true') { msgNotify('删除成功!'); } else { msgNotify('删除失败!'); }; //删除div $('#' + fileId + 'div').remove(); //删除input中的对应图片名 if (data.msg.toLowerCase() == 'true') { var fileNames = $('#' + this.targetInput).val(); fileNames = fileNames.replace(eval("/" + this.fileName + "/gi"), ''); $('#' + this.targetInput).val(fileNames); }; }); }; //绑定上传控件change事件 FileUploader.prototype.uploaderChange = function () { //设置easyui $('#' + this.targetId + ' span span').html('正在上传中'); $('#' + this.targetId).unbind('click'); //提交表单 this.iframeName = 'uploadIframe' + Math.random(); var iframe = $('<iframe width="0" height="0" frameborder="0" name="' + this.iframeName + '">'); iframe.appendTo($('body')); $('#' + this.uploadFormId).attr('target', iframeName); $('#' + this.uploadFormId).submit(); }; //绑定iframe 加载完成事件 FileUploader.prototype.iframeOnload = function () { //设置Easyui $('#' + this.targetId + ' span span').html('选择打款凭证'); $('#' + this.targetId).bind('click', function () { $('#' + this.uploadInputId).click(); }); //读取iframe页面回传的值 this.fileName = $(window.frames[this.iframeName].document).find("input").val(); //添加图片 this.appendPic(); };

      

  • 相关阅读:
    描述下jvm的gc机制,常用的jvm调优方法,oom如何产生,如何处理oom 问题?
    大数据hadoop 面试经典题
    redis 个人理解和常用命令以及应用场景
    Hadoop 源码编译 step by step 最简洁的步骤
    Openstack 的介绍 ,安装以及简单应用
    Docker 的介绍 ,安装以及简单应用
    星型模型和雪花模型的应用场景
    php向js的函数内传递参数-用经纬度计算2点间的距离
    php-URL方法下载远程图片
    微信开发-js接口的使用无法使用分享功能的一些说明
  • 原文地址:https://www.cnblogs.com/wuMing-dj/p/3588093.html
Copyright © 2020-2023  润新知