日期:2014-05-16  浏览次数:20384 次

JS模拟弹窗,IE下出现错误。
用了个模拟弹窗,在Chrome下一切正常。

但在IE下:
1,位置错误(出现在页面最低端),
2,header不见了,
3,无法实现拖动。

请教一下如何解决。

IE:

Chrome:



function $(id){return document.getElementById(id);}
//var isIE = (document.all) ? true : false;
function Box(objID,W,H,inner,footerInner){
var objHead,objBody,objFooter,inner,footerInner;
if(!$(objID)){
//创建html结构并赋id以及class
var obj = document.createElement("div");
var objHead = document.createElement("div");
var objBody = document.createElement("div");
var objFooter = document.createElement("div");
obj.id=objID;
obj.className="lightBox";
objHead.id=objID+"_head";
objBody.id=objID+"_body";
objFooter.id=objID+"_footer";
objHead.className="Boxheader";
objBody.className="Boxbody";
objFooter.className="Boxfooter";
obj.appendChild(objHead);
obj.appendChild(objBody);
obj.appendChild(objFooter);
document.body.appendChild(obj);
//如果参数为空时的处理
if(W==undefined||W<200||W==""){W=200}//最小宽度
if(H==undefined||H<60||H==""){H=60}
if(inner==undefined || inner=="" ){inner="2013 Vinc.Jie, All rights reserved."}
if(footerInner==undefined || footerInner=="" ){footerInner="2013 Vinc.Jie, All rights reserved."}//页脚没有内容时默认值
var BodyLid = objID+"BodyL",BodyRid = objID+"BodyR",headerLid = objID+"headerL",FooterLid= objID+"FooterL",closeBtn= objID+"closeBtn",cancelBtn =objID+"cancel";
objBody.innerHTML='<div class="BodyL" id='+BodyLid+'>'+inner+'</div><div class="BodyR" id='+BodyRid+'></div>';
objHead.innerHTML='<div class="headerL" id='+headerLid+'><span style="float:right;background:url(lightbox-close.png) no-repeat 0 center;display:inline-block;height:46px;width:16px;cursor:pointer;" id='+closeBtn+'></span></div><div class="headerR"></div>';
objFooter.innerHTML='<div class="FooterL" id='+FooterLid+'>'+footerInner+'</div><div class="FooterR"></div>';
//js样式设置
$(BodyLid).style.height=H+"px";
$(BodyLid).style.width=W+"px";
$(FooterLid).style.width=$(headerLid).style.width=W+"px";
$(BodyRid).style.height=$(BodyLid).clientHeight+"px";
obj.style.cssText+=";position:fixed;left:50%;top:50%;z-index:901"; //;
obj.style.marginLeft=-obj.scrollWidth/2+"px";
obj.style.marginTop=-obj.scrollHeight/2+"px";
document.body.style.cssText+="height:100%;overflow:hidden;";
var mask=0;//是否创建遮罩层
if(mask){
var objMask = document.createElement("div");
objMask.id="Mask";objMask.className="BoxMask";
document.body.appendChild(objMask);objMask.style.cssText+=";position:fixed;";//z-index:900;
objMask.style.height=document.documentElement.scrollHeight+document.documentElement.scrollTop+"px";
}




$(closeBtn).onclick = function(){Close(objID);};//关闭按钮

//if($(cancelBtn)){$(cancelBtn).onclick = function(){Close(objID);}}//取消按钮
$(cancelBtn).onclick = function(){Close(objID);};//取消按钮

//拖动功能
//if(evt.keycode==27){alert("esc")};
var w = obj.scrollWidth,h = obj.scrollHei