rt,
功能是这样的,弹出层调用的是js
具体页面如下:
1.父页面 divtest.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script  type="text/javascript" src="../CJS/jquery.js"></script>
<script  type="text/javascript" src="../CJS/Common.js"></script><script>
 function openwindow()
      {
    openPopWidow("create",1000,600,'<b>PAYMENT</b>','aa.htm','#58a4cb');
      }
</script>
<body>
<div id="create"></div><input type="button"  value="open" onClick="openwindow()"></body>
</html>2.弹出的子页面 aa.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
你好,欢迎加入!
<input type="button"  value="关闭"></body>
</html>
问题:在子页面的button事件中,怎样关闭弹出的层?

解决方案 »

  1.   

    3.Common.js
    //全局变量定义
    var HKMLWidow_zindex=1000;    
    var HKMLWidow_x0=0,HKMLWidow_y0=0,HKMLWidow_x1=0,HKMLWidow_y1=0;
    var HKMLWidow_offx=6,HKMLWidow_offy=6;
    var HKMLWidow_moveable=false;
    function openNewWindow(PageID,width,height,title,data,color,left,top)
    {
        var ScreenInfo = getScreenInfo();
        if(left == null){
           left  = Math.round((ScreenInfo.Width - width) / 2);
        }
    if(ScreenInfo.Width <= width) left=20;  
    if(top == null){
           top = Math.round((ScreenInfo.Height - height) / 2);
        }
        if(ScreenInfo.Height <= height) top=20; 
        if(color == null){
           color = "#33CCCC";
        }
        var AddStepWindow = new HKMLWidow(PageID,PageID,width,height,left,top,title,data,color);
        AddStepWindow.Create();
    }function HKMLWidow(ContentID,id,width,height,left,top,title,data,color)
    {
        HKMLWidow_zindex = HKMLWidow_zindex + 2;
        //alert(HKMLWidow_zindex);
        this.ID     = id;
        this.width  = width;
        this.height = height;
        this.left   = left;
        this.top    = top;
        this.zIndex = HKMLWidow_zindex;
        this.title  = title;
        this.data   = data;
        this.color  = color;
        this.Create = function(){
            var str="";
            str += "<div id=\"HKML_NEWWIN_" + this.ID + "\" align=\"center\" onmousedown=\"HKML_OnGetFocus(this)\" style=\"z-index:" + this.zIndex + ";width:" + this.width + "px;height:" + this.height + "px;left:" + this.left + "px;top:" + this.top + "px;background-color:" + this.color + ";font-size:12px;font-family:Verdana;position:absolute;cursor:default\">";
            str += "    <b style=\"display:block;background: #FFFFFF\">";
            str += "    <b style=\"display:block;height: 1px;overflow: hidden; background: " + this.color + ";margin: 0 4px\"></b>";
            str += "    <b style=\"display:block;height: 1px;overflow: hidden; background: " + this.color + ";margin: 0 3px\"></b>";
            str += "    <b style=\"display:block;height: 1px;overflow: hidden; background: " + this.color + ";margin: 0 2px\"></b>";
            str += "    <b style=\"display:block;height: 1px;overflow: hidden; background: " + this.color + ";margin: 0 1px;height: 1px\"></b></b> ";
            str += "    <div onmousedown=\"HKML_OnStartMove(this)\" onmouseup=\"HKML_OnStopMove(this)\" onmousemove=\"HKML_OnMove(this)\" style=\"background-color: " + this.color + ";width:99%;height:18px;color:white;float:left\">";
            str += "       <div style=\"float:left;font-size:14px;\">&nbsp;" + this.title + "</div>";
            str += "       <div style=\"font-family:webdings;float:right\" onclick=\"HKML_Close(this)\">r</div>";
            str += "       <div style=\"font-family:webdings;float:right\" onclick=\"HKML_MinWin(this)\">0</div></div>";
            str += "    <div style=\"width:" + (this.width-8) + "px;height:" + (this.height-29) + "px;background-color:white;line-height:14px;word-break:break-all;padding:3px;filter:alpha(opacity=95)\">" + this.data + "</div>";
            str += "</div>";
            $("#"+ContentID).html(str);
        }

    //获得焦点
    HKML_OnGetFocus = function(obj){
       var idx = HKMLWidow_zindex+2;
       obj.style.zIndex=idx;
       if(obj.nextSibling !=null){
           obj.nextSibling.style.zIndex=idx-1;
       }
    }
    //拖动;
    HKML_OnMove = function(obj){
       var win = obj.parentNode;
       if(HKMLWidow_moveable){
          win.style.left = HKMLWidow_x1 + event.clientX - HKMLWidow_x0;
          win.style.top = HKMLWidow_y1 + event.clientY - HKMLWidow_y0;
       }
    }
    HKML_OnStartMove = function(obj){
       //锁定标题栏;
       obj.setCapture();
       var win = obj.parentNode;
       HKMLWidow_x0 = event.clientX;
       HKMLWidow_y0 = event.clientY;
       HKMLWidow_x1 = parseInt(win.style.left);
       HKMLWidow_y1 = parseInt(win.style.top); 
       HKMLWidow_moveable = true;
    }
    HKML_OnStopMove = function(obj){
       obj.releaseCapture();
       HKMLWidow_moveable = false;
    }
    //最小化窗口/还原窗口
    HKML_MinWin = function(obj){
       var win = obj.parentNode.parentNode;
       var tit = obj.parentNode;
       var msg = tit.nextSibling;
       var flg = msg.style.display == "none";
       if(flg){
           win.style.height = parseInt(msg.style.height) + parseInt(tit.style.height) + 11;
           msg.style.display = "block";
           obj.innerHTML = "0";
       }else{
           win.style.height = parseInt(tit.style.height) + 11;
           obj.innerHTML = "2";
           msg.style.display = "none";
       }
    }
    //关闭窗口
    HKML_Close = function(obj){
       var win = obj.parentNode.parentNode;
       win.parentNode.removeChild(win);
    }
    function escape2(str){
    return escape(str).replace(/\+/g,"%2b");
    }
    function GetVal(ID)
    {
      return escape2($('#'+ID).val());
    }function getScreenInfo()
    {
        var Top = document.documentElement.scrollTop;
        var Left = document.documentElement.scrollLeft;
        var Height = document.documentElement.clientHeight;
        var Width = document.documentElement.clientWidth;
        return {Top:Top,Left:Left,Height:Height,Width:Width};
    }
    function OnInlitDiv(ID,myHeigth,myWidth,StyleNum)
    {
    var Height = parseInt(myHeigth);
    var Width = parseInt(myWidth);
    var obj =$("#"+ID);
    obj.css("display","block");
    obj.css("position","absolute");
    obj.css("width",Width + "px");
    obj.css("height",Height + "px");
    obj.css("z-index",StyleNum<0?1000:StyleNum);
    DivAdjust(obj)
    // window.onscroll = function()
    //    {
    //        DivAdjust(obj)
    //    };
    }
    function RemoveDiv(ID)
    {
       var obj =$("#"+ID);
       obj.removeAttr("style");
       obj.css("display","none");
       obj.html("");
       //obj.hide();
    }function DivAdjust(obj)
    {
        var ScreenInfo = getScreenInfo();
        var leftAdd = Math.round((ScreenInfo.Width-obj.width())/2);
    if(ScreenInfo.Width<=obj.width()) leftAdd=20;    //自动调整最大宽度
        var topAdd = Math.round((ScreenInfo.Height-obj.height())/2);
        if(ScreenInfo.Height<=obj.height()) topAdd=20; //自动调整最大高度
        obj.css("top",(ScreenInfo.Top + topAdd) + "px");
    obj.css("left",(ScreenInfo.Left + leftAdd) + "px");
    }function CommonAjaxGet(Para,ContentID,GetWay,TitleID)
    {
        $.get("../AjaxPage.aspx", Para, function (XmlStr, textStatus){
                   var data=AppError(XmlStr);
                   if(data!="")
                   {
                      if(GetWay=='1')
                       {
                           $("#"+ContentID).append(data);
                       }
                       else
                       {
                           $("#"+ContentID).html(data);
                       }
                       if(TitleID.length>0)
                       {
                           OnInlitDivMove('TitlePart');
                       }
                   } 
              });
    }
    function CommAjaxPost(Para,ContentID,GetWay,TitleID)
    {
        $.ajax({
            url:"../AjaxPage.aspx",
            dataType:"xml",
            type:"post",
            success:function(XmlStr){
                   var data=AppError(XmlStr);
                   if(data!="")
                   {
                      if(GetWay=='1')
                       {
                           $("#"+ContentID).append(data);
                       }
                       else
                       {
                           $("#"+ContentID).html(data);
                       }
                       if(TitleID.length>0)
                       {
                           OnInlitDivMove('TitlePart');
                       }
                   }           
                }
            });
    }
    //处理返回回来的XML资料
    function AppError(XmlStr)
    {
        if($(XmlStr).find("messagetype").eq(0).text()=="0000")
        {
           return $(XmlStr).find("content").eq(0).text();
        }
        else
        {
           alert($(XmlStr).find("content").eq(0).text());
           return "";
        }
    }function CreateWebEditor(ID,heigth,InlitStr,ToolBar,BasePath)
    {
         var sBasePath = BasePath==null? '../WebEditor/':BasePath ;
         var oFCKeditor = new FCKeditor(ID) ;
         oFCKeditor.BasePath = sBasePath ;
         oFCKeditor.Height = heigth ;
         oFCKeditor.Value = InlitStr ;
         //oFCKeditor.Create() ;
         return oFCKeditor.CreateHtml();
    }
      

  2.   

    1.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <div id="demodiv">demodiv</div>
    <iframe src="2.html" />
    </body>
    </html>
    2.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <button onclick="closepdiv()">88888888888888888</button>
    <script type="text/javascript">
    function closepdiv(){
    try{
    parent.document.getElementById("demodiv").style.display='none';
    }catch(e){}
    }
    </script>
    </body>
    </html>
      

  3.   


    可以在子页面调用父页面的方法。
    HKML_Close = function(obj){
       var win = obj.parentNode.parentNode;
       win.parentNode.removeChild(win);
    }function close() {
        window.parent.HKML_Close(o);//调用父页面的close方法
    }
      

  4.   


    调用了该方法
    但是只是关闭了弹出的aa.htm中的内容,弹出层并没有关闭...
      

  5.   

    opener.document.getElementById("create").style.display='none';