bob体育官方平台
透过Javascript创造贰个选拔文件的对话框代码_javascript技能_脚本之家

AJAXLightBox

' + '取消

  • One
  • Two

'; new NeatDialog; } //关闭并移除弹窗 NeatDialog.prototype.close = function { this.elt.style.display = "none"; this.elt.parentNode.removeChild; } window.neatDialog = null; } //创立弹窗 function NeatDialog { window.neatDialog = null; this.elt = null; if (document.createElement && document.getElementById卡塔尔国 { var dg = document.createElement; dg.className = "neat-dialog"; if sHTML = '

TheCarreraGThasa5.7litreV10internalcombustionenginethatproduces 605SAEhorsepower.Porscheclaimsitwillacceleratefrom0to100 km/hin3.9secondsandhasamaximumspeedof330km/h. With605hp,thecarweighs1,380kg.TheCarreraGTisonly offeredwithasix-speedmanualtransmission,incontrasttoitsrivalthe FerrariEnzothatisonlyofferedwithsequentialmanualtransmission.Also theCarreraGTissignificantlylessexpensivethantheFerrariEnzo.The FerrariEnzoispricedaround$660,000totheCarreraGT's$440,000.The CarreraGTisknownforitshighqualityandreliabilitywhichmakesitoneof thebestsupercarsever. FerrariTestarossa

n' + sHTML; dg.innerHTML = sHTML; var dbg = document.createElement; dbg.id = "nd-bdg"; dbg.className = "neat-dialog-bg"; var dgc = document.createElement; dgc.className = "neat-dialog-cont"; dgc.appendChild; dgc.appendChild; if (document.body.offsetLeft > 0) { dgc.style.marginLeft = document.body.offsetLeft + "px"; } document.body.appendChild; this.elt = dgc; window.neatDialog = this; } } 效果:

此外,还索要设置该页面所运用CSS样式。lightbox.css样式表文件代码如下所示: #lightbox{ BORDER-RIGHT:#fff1pxsolid; BORDER-TOP:#fff1pxsolid; DISPLAY:none; Z-INDEX:9999; BACKGROUND:#fdfce9; LEFT:50%; MARGIN:-220px0px0px-250px; BORDER-LEFT:#fff1pxsolid; WIDTH:500px; BORDER-BOTTOM:#fff1pxsolid; POSITION:absolute; TOP:50%; HEIGHT:400px; TEXT-ALIGN:left } UNKNOWN{ POSITION:fixed } #overlay{ DISPLAY:none; Z-INDEX:5000;FILTER:alpha; LEFT:0px; WIDTH:100%; POSITION:absolute; TOP:0px; HEIGHT:100%; BACKGROUND-COLOR:#000;moz-opacity:0.8;opacity:.80 } UNKNOWN{ POSITION:fixed } .done#lightbox#lbLoadMessage{ DISPLAY:none } .done#lightbox#lbContent{ DISPLAY:block } .loading#lightbox#lbContent{ DISPLAY:none } .loading#lightbox#lbLoadMessage{ DISPLAY:block } .done#lightboxIMG{ WIDTH:100%;HEIGHT:百分之百 } 顾客端脚本 由于浏览器对图层的援助差异,所以率先要鲜明客户端浏览器的花色。以下代码可用来推断顾客端的浏览器和操作系统。 vardetect=navigator.userAgent.toLowerCase(卡塔尔(قطر‎; varOS,browser,version,total,thestring; functiongetBrowserInfo(卡塔尔(قطر‎{ if{ browser="Konqueror"; OS="Linux"; } elseifbrowser="Safari" elseifbrowser="OmniWeb" elseifbrowser="Opera" elseifbrowser="WebTV"; elseifbrowser="iCab" elseifbrowser="InternetExplorer" elseif(!checkIt{ browser="NetscapeNavigator" version=detect.charAt; } elsebrowser="Anunknownbrowser"; ifversion=detect.charAt(place+thestring.length卡塔尔国; if{ ifOS="Linux"; elseifOS="Unix"; elseifOS="Mac" elseifOS="Windows" elseOS="anunknownoperatingsystem"; } } functioncheckIt{ place=detect.indexOf+1; thestring=string; returnplace; } 上面看一下网页加载时须求加多的办法。有关网页加载和起头化方法代码如下: //网页加载调用initialize和getBrowserInfo方法 伊芙nt.observe(window,'load',initialize,false卡塔尔; Event.observe(window,'load',getBrowserInfo,falseState of Qatar; //未加载时清空缓存 Event.observe(window,'unload',伊夫nt.unloadCache,false卡塔尔; //开始化方法 functioninitialize(卡塔尔{ //调用该措施为该页增多覆盖层和高亮彰显层 addLightboxMarkup(State of Qatar; //为每一个可高亮显示的因素创立lightbox对象 lbox=document.getElementsByClassName; for(i=0;i'; bod.appendChild; bod.appendChild; } 封装lightbox类 伊始化数据时,为种种可高亮呈现的链接创立了lightbox对象。该类的代码具体贯彻如下: varlightbox=Class.create(State of Qatar; lightbox.prototype={ yPos:0, xPos:0, //构造方法,ctrl为开创该对象的要素 initialize:function{ //将该因素的链接赋值给this.content this.content=ctrl.href; //为该因素增添onclick事件activate方法 Event.observe(ctrl,'click',this.activate.bindAs伊夫ntListener; ctrl.onclick=function(卡塔尔国{returnfalse;}; }, //当单击链接时 activate:function(卡塔尔(قطر‎{ if(browser=='InternetExplorer'卡塔尔(قطر‎{//判定为IE浏览器 this.getScroll(卡塔尔国; this.prepareIE; this.setScroll; this.hideSelects;//隐讳全数的标志 } //调用该类中的displayLightbox方法 this.displayLightbox; }, prepareIE:function{ bod=document.getElementsByTagName[0]; bod.style.height=height; bod.style.overflow=overflow; htm=document.getElementsByTagName[0]; htm.style.height=height; htm.style.overflow=overflow; }, hideSelects:function{ selects=document.getElementsByTagName; for(i=0;i"; //在info成分前插入多少个要素 newInsertion.Before,info卡塔尔(قطر‎//改造该因素的classname的值 $.className="done"; //调用本类中actions方法 this.actions(State of Qatar; varctrl=$; //为高亮层加多事件管理方法reset Event.observe(ctrl,'click',this.reset.bindAs伊芙ntListener; ctrl.onclick=function(卡塔尔{returnfalse;}; }, //恢复生机最初状态 reset:function(State of Qatar{ //隐讳覆盖层 $.style.display="none"; //清空重返数据 $.innerHTML=""; //隐蔽高亮层 $.style.display="none"; }, //Searchthroughnewlinkswithinthelightbox,andattachclickevent actions:function(卡塔尔国{ lbActions=document.getElementsByClassName; for(i=0;i PorscheCarreraGT

' + sTitle + '

TheFerrariTestarossaisanV12mid-enginedsportscarmadebyFerrari. Thename,whichmeans"redhead",comesfromtheredpaintedcylinderheadson theflat-12engine.Theenginewastechnicallya180?Venginesinceitshared flat-planecrankshaftpinswithopposingcylinders.Outputwas390hp,andthecarwonmanycomparisontestsandadmirers-itwasfeaturedon thecoverofRoad&Trackmagazineninetimesinjustfiveyears.Almost 10,000Testarossas,512TRs,and512Mswereproduced,makingthisoneofthe mostcommonFerrarimodelsdespiteitshighpriceandexoticdesign.

CSS 样式: 复制代码 代码如下: DIV.neat-dialog-cont { Z-INDEX: 98; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: 0px; WIDTH: 百分百; POSITION: absolute; TOP: 0px; HEIGHT: 百分百 } DIV.neat-dialog-bg { Z-INDEX: -1; FILTE福睿斯: 阿尔法; LEFT: 0px; WIDTH: 百分百; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-COLO帕杰罗: #eee; opacity: 0.7; } DIV.neat-dialog { BORDER-RIGHT: #555 1px solid; BORDER-TOP: #555 1px solid; Z-INDEX: 99; MARGIN-LEFT: 35%; BORDER-LEFT: #555 1px solid; WIDTH: 300px; MARGIN-RIGHT: auto; BORDER-BOTTOM: #555 1px solid; POSITION: relative; TOP: 25%; BACKGROUND-COLOR: #fff } DIV.neat-dialog-title { PADDING-RIGHT: 0.3em; PADDING-LEFT: 0.3em; FONT-SIZE: 1em; PADDING-BOTTOM: 0.1em; MARGIN: 0px; LINE-HEIGHT: 1.2em; PADDING-TOP: 0.1em; BORDER-BOTTOM: #444 1px solid; POSITION: relative;background: #36C;color:White; } DIV.neat-dialog P { PADDING-PRADOIGHT: 0.2em; PADDING-LEFT: 0.2em; PADDING-BOTTOM: 0.2em; PADDING-TOP: 0.2em; TEXT-ALIGN: center } Javascript 代码 : 复制代码 代码如下: //张开弹窗 function f_OpenDialog() { var sHTML = '

返回顶部