function getId(id){ return document.getElementById(id); } function Box_detail(objID,W,H,inner,classname_re,title,isclose){ var objHead,objBody,objFooter,inner,TitleImg,BoxCloseBtn,TitleTip; if(!getId(objID)){ //创建html结构并赋id以及class var obj = document.createElement("div"); var objHead = document.createElement("div"); var objBody = document.createElement("div"); obj.className=classname_re; objHead.className=classname_re+"_Header"; objBody.className=classname_re+"_Body"; TitleImg=classname_re+"_TitleImg"; BoxCloseBtn=classname_re+"_BoxCloseBtn"; TitleTip=classname_re+"_TitleTip"; if(isclose){ BoxCloseBtn=classname_re+"_BoxCloseBtn_Cz"; } obj.id=objID; objHead.id=objID+"_head"; objBody.id=objID+"_body"; obj.appendChild(objHead); obj.appendChild(objBody); document.body.appendChild(obj); //如果参数为空时的处理 if(W==期货||W<200||W==""){W=200}//最小宽度 if(H==期货||H<60||H==""){H=60} var cancelBtn =objID+"cancel",closeBtn= objID+"closeBtn"; objHead.innerHTML=''+title+''; objBody.innerHTML=inner; //js样式设置 getId(objHead.id).style.width=W+"px" getId(objBody.id).style.width=W+"px"; getId(objBody.id).style.height=getId(objBody.id).clientHeight+"px"; obj.style.cssText+=";position:absolute;left:50%;top:50%;z-index:901; "; obj.style.marginLeft=-obj.scrollWidth/2+"px"; obj.style.marginTop=-obj.scrollHeight/3+"px"; document.body.style.cssText+="height:100%;overflow:auto;"; var mask=1;//是否创建遮罩层 if(mask){ var objMask = document.createElement("div"); objMask.id="Mask";objMask.className="BoxMask_zz"; document.body.appendChild(objMask);objMask.style.cssText+=";position:fixed;z-index:900;_position:absolute;_height:2720px;"; } function Close(objID){ document.body.removeChild(getId(objID));document.body.style.cssText+="width:100%;overflow:auto;"; if(objMask){document.body.removeChild(objMask)} } getId(closeBtn).onclick = function(){Close(objID)};//关闭按钮 //拖动功能 var w = obj.scrollWidth,h = obj.scrollHeight; var iWidth = document.documentElement.clientWidth; var iHeight = document.documentElement.clientHeight; var moveX = 0,moveY = 0,moveTop = 0,moveLeft = 0,moveable = false; objHead.onmousedown = function(e) { moveable = false; e = window.event?window.event:e; moveX = e.clientX-obj.offsetLeft; moveY = e.clientY-obj.offsetTop; obj.style.zIndex++; document.onmousemove = function(e) { if (moveable) { e = window.event?window.event:e; var x = e.clientX - moveX; var y = e.clientY - moveY; if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) { obj.style.left = x + "px"; obj.style.top = y + "px"; obj.style.margin = "auto"; } } } document.onmouseup = function () {moveable = false;}; } }else(alert("弹层已经打开!")); }