Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1179251
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: JavaScript

2013-09-30 18:07:15


点击(此处)折叠或打开

  1. var jsUpload = new function(){
  2.     this.hiddenFrameId = 'js_upload_frame';
  3.     this.uploadCallBack;
  4.     this.getHiddenFrame = function(){
  5.         if(this.loginWin==null){
  6.             this.loginWin=document.getElementById(this.hiddenFrameId);
  7.         }
  8.         if(this.loginWin==null){
  9.             var div=document.createElement("div");
  10.             div.id="material_upload_frame_container";
  11.             div.style.display="none";
  12.             document.body.appendChild(div);
  13.             var frameHtml='';
  14.             div.innerHTML=frameHtml;
  15.             this.loginWin=document.getElementById(this.hiddenFrameId);
  16.         }
  17.         return this.loginWin
  18.     }
  19.     this.frameCallback = function(json){
  20.         var logWin=document.getElementById(this.hiddenFrameId),response="";
  21.         if(json){
  22.             response=json
  23.         }else{
  24.             try{
  25.                 response=logWin.contentWindow.document.body.innerHTML
  26.             }catch(e){
  27.                 location.reload()
  28.             }
  29.         }
  30.         if(response!=""&&response.length<6000){
  31.             pos1=response.indexOf("{");
  32.             pos2=response.lastIndexOf("}");
  33.             if(pos1>=0&&pos2>0){
  34.                 response=response.substring(pos1,pos2+1)
  35.             }else{
  36.                 response="{}"
  37.             }
  38.             var result={},param={};
  39.             response=response.replace(/\r/g,"").replace(/\n/g,"");
  40.             try{
  41.                 eval("result="+response)
  42.             }catch(e){
  43.             }
  44.             if (typeof this.uploadCallBack=='function') {
  45.                 this.uploadCallBack(result);
  46.             } else {
  47.                 if(result['errno']!=0){
  48.                     alert(result['errmsg']);
  49.                 }
  50.             }
  51.         }
  52.     }
  53.     this.setUploadCallBack = function(func){
  54.         this.uploadCallBack = func;
  55.     }
  56.     this.upload = function(form, callback){
  57.         if (typeof callback=='function'){
  58.             this.setUploadCallBack(callback);
  59.         }
  60.         this.getHiddenFrame();
  61.         form.target = this.hiddenFrameId;
  62.         form.submit();
  63.     }
  64. };

阅读(876) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~