javascript快顯視窗實現動態檔案上傳

來源:互聯網
上載者:User

javascript快顯視窗實現動態檔案上傳

function showWin(title,html,width,height,modal,type,url){//設定視窗大小if(width<400){width=400;}if(height<200){height=200;}//body內邊大小var cw=document.body.clientWidth;var ch=document.body.clientHeight;//文字框大小var sw=document.body.scrollWidth;var sh=document.body.scrollHeight; //可見地區座標var st = document.body.scrollTop;var sl = document.body.scrollLeft;var w=cw>sw?cw:sw;var h=ch>sh?ch:sh;//建立模態if(modal){var mask=document.createElement("div");mask.style.cssText = "position:absolute;left:0;top:0px;background:#fff;filter:Alpha(Opacity=30);opacity:0.5;z-index:100;width:" + w + "px;height:" + h + "px;";document.body.appendChild(mask);}// 建立主視窗var win=document.createElement("div");win.style.cssText="position:absolute;left:" + (sl + cw/2 - width/2) + "px;top:" + (st + ch/2 - height/2) + "px;background:#f0f0f0;z-index:101;width:" + width + "px;height:" + height + "px;border:solid 2px #afccfe;";//標題列目var tBar=document.createElement("div");tBar.style.cssText="margin:0;width:" + width + "px;height:25px;background:green;cursor:move;";//給標題列加文字var tText=document.createElement("div");tText.style.cssText="float:left;margin-left:30px;text-align:center;height:25px;line-height:25px;width:"+(width-80)+"px;";tText.innerHTML=title;tBar.appendChild(tText);//添加關閉按鈕var  closeButton=document.createElement("div");closeButton.style.cssText="float:right;width:20px;margin:3px;cursor:pointer;color:red;";closeButton.innerHTML="X";tBar.appendChild(closeButton);win.appendChild(tBar);//視窗主體var bodyCon=document.createElement("div");bodyCon.style.cssText="text-align:left;width:" + width + "px;height:" + (height -50) + "px;overflow:auto;";switch(type){case "file":var formCon=document.createElement("form");formCon.action=url;formCon.method="post";formCon.enctype="multipart/form-data";formCon.target="hidFram";formCon.id="formCon";formCon.name="formCon";formCon.innerHTML="請選擇檔案:"+html;bodyCon.appendChild(formCon);var framCon=document.createElement("iframe");framCon.name="hidFram";framCon.id="hidFram";framCon.style.cssText="width:400px;height:200px;";bodyCon.appendChild(framCon);//當framCon內容載入完時,設定內容framCon.onload = function(){    $res=framCon.contentWindow.document.body.innerHTML;alert($res+"Local iframe is now loaded.");}break;default:bodyCon.innerHTML=html;}win.appendChild(bodyCon);//表單底部的按鈕部分var btnCon = document.createElement('div');btnCon.style.cssText = "width:" + width + "px;height:25px;text-height:20px;background:#EED5B7;text-align:center;padding-top:3px;";var subButton=document.createElement("button");subButton.style.cssText="float:right;";subButton.name="submit";subButton.innerHTML="確定";btnCon.appendChild(subButton);//使用者填充按鈕之間的空白var nbsp = document.createElement('label');nbsp.innerHTML = "  ";btnCon.appendChild(nbsp);var celButton=document.createElement("button");celButton.style.cssText="float:right;";celButton.name="cancel";celButton.innerHTML="取消";btnCon.appendChild(celButton);win.appendChild(btnCon);document.body.appendChild(win); //添加關閉按鈕//var closeBt=document.createElement("button");//closeBt.innerHTML="關閉";//拖動視窗//滑鼠座標var mouseX=0;var mouseY=0;//視窗相對座標var toTop=0;var toLeft=0;//判斷滑鼠是否可以移動var moveable=false;//標題列被按下時初始化資料tBar.onmousedown=function(){var action=getEvent();moveable=true;mouseX=action.clientX;mouseY=action.clientY;toTop=parseInt(win.style.top);toLeft=parseInt(win.style.left);tBar.onmousemove=function(){if(moveable){   var eve=getEvent();   var x=toLeft+eve.clientX-mouseX;   var y=toTop+eve.clientY-mouseY;   //判斷是否在視窗裡面   if(x>0&&(x+width0&&(y+height

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.