function openNewDiv(_id,title,innerhtml,width,height) 
{
    if (docEle(_id)) document.body.removeChild(docEle(_id));
    //新弹出层
    var newDiv = document.createElement("div");
    newDiv.id = _id;
newDiv.className='newdiv'; //设定新DIV的样式newdiv
    newDiv.style.position = "absolute"; 
    newDiv.style.zIndex = "9999";
//新DIV的宽和高
    newDivWidth = parseInt(width);
    newDivHeight = parseInt(height);
    newDiv.style.width = newDivWidth + "px";
    newDiv.style.height = newDivHeight + "px";
//定位新的DIV
    newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
    newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
//如果标题不为空
if(!isNull(title)){
//标题DIV class为divhead
title="<span class='divhead'>"+title+"</span><a href='#' name='divcolse'>关闭</a>";
innerhtml=title+innerhtml;
}
newDiv.innerHTML = innerhtml; document.body.appendChild(newDiv);     //弹出层滚动居中
function newDivCenter()
{
   newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
    newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
}
    if(document.all)
    {
        window.attachEvent("onscroll",newDivCenter);
    }
    else
    {
        window.addEventListener('scroll',newDivCenter,false);
    }
    
    //关闭新图层和mask遮罩层

    var newA = document.createElement("image");
    newA.src ="./images/htmlimage/back.gif";
    newA.onclick = function(){
if(document.all)
        {
            window.detachEvent("onscroll",newDivCenter);
        }
        else
        {
            window.removeEventListener('scroll',newDivCenter,false);
        }
        document.body.removeChild(docEle(_id));
        return false;
}
    newDiv.appendChild(newA);
}此代码在IE下可以正常运行,在FF下能弹出窗口。请高手帮忙修改修改,小弟对JS实在不熟。
现在只有这么点分了,我会努力赚分,有分了接着加分
顺便鄙视Microsoft鄙视Netscape,丫们光TM知道赚钱

解决方案 »

  1.   

    修改好了,测试通过,如果你图片在ff下无法显示的话请注意你的src用file:\\\形式<script type="text/javascript">
    var docEle = function()
    {
        return document.getElementById(arguments[0]) || false;
    }function openNewDiv(_id)
    {
        var m = "mask";
        if (docEle(_id)) document.body.removeChild(docEle(_id));
        if (docEle(m)) document.body.removeChild(docEle(m));    //mask遮罩层    var newMask = document.createElement("div");
        newMask.id = m;
        newMask.style.position = "absolute";
        newMask.style.zIndex = "1";
        _scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
        _scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
        newMask.style.width = _scrollWidth + "px";
        newMask.style.height = _scrollHeight + "px";
        newMask.style.top = "0px";
        newMask.style.left = "0px";
        newMask.style.background = "#33393C";
        newMask.style.filter = "alpha(opacity=40)";
        newMask.style.opacity = "0.40";
        document.body.appendChild(newMask);    //新弹出层    var newDiv = document.createElement("div");
        newDiv.id = _id;
        newDiv.style.position = "absolute";
        newDiv.style.zIndex = "9999";
        newDivWidth = 400;
        newDivHeight = 200;
        newDiv.style.width = newDivWidth + "px";
        newDiv.style.height = newDivHeight + "px";
        newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
        newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
        newDiv.style.background = "#EFEFEF";
        newDiv.style.border = "1px solid #860001";
        newDiv.style.padding = "5px";
        newDiv.innerHTML = "弹出层内容 ";
        document.body.appendChild(newDiv);    //弹出层滚动居中    function newDivCenter()
        {
            newDiv.style.top = (document.body.scrollTop + document.body.clientHeight/2 - newDivHeight/2) + "px";
            newDiv.style.left = (document.body.scrollLeft + document.body.clientWidth/2 - newDivWidth/2) + "px";
        }
        if(document.all)
        {
            window.attachEvent("onscroll",newDivCenter);
        }
        else
        {
            window.addEventListener('scroll',newDivCenter,false);
        }    //关闭新图层和mask遮罩层
     var newA = document.createElement("img");
        newA.src ="2.jpg";
        newA.onclick = function(){
            if(document.all)
            {
                window.detachEvent("onscroll",newDivCenter);
            }
            else
            {
                window.removeEventListener('scroll',newDivCenter,false);
            }
            document.body.removeChild(docEle(_id));
            document.body.removeChild(docEle(m));
            return false;
        }
        newDiv.appendChild(newA);}
    </script>
    <body><a onclick="openNewDiv('newDiv');return false;" style="cursor:pointer">弹出层</a>
    </body>
      

  2.   

    document.body这个玩意兼容也不好哦,在不同的浏览器,解析有所不同的
      

  3.   

    改成document.documentElement
    就比如说:document.documentElement.scrollTop和document.body.scrollTop
    他们的结果是不一样的
      

  4.   

    这个还有几个问题.跟这帖子问题一样
    http://topic.csdn.net/u/20090918/23/36046d9d-b5c2-4e89-9cac-e78979b610da.html?35569
      

  5.   

    鄙视FF没有道理呀,FF的JS引擎是按照标准做的。
    总不能要求所有的浏览器都向微软看齐吧?
      

  6.   

    问题我已经解决了,大概就是用xmlhttprequest对象方法时没有注意大小写,在这里提醒各位仁兄仁姐,一定要书写标准的代码啊~~