document.write()是容易让页面其他的内容变没有了。你可以用form.innerHTML += "<div></div>"这种方式实现啊

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script language="javascript" type="text/JavaScript">
    //首先定义两个数组,一个是菜单文字,一个是链接
        var MenuText = new Array(3);
        var MenuEven = new Array(3);
        MenuText[1] = ["菜单11","菜单12","菜单13"];
        MenuText[2] = ["菜单21","菜单21"];
        MenuText[3] = ["菜单31","菜单321","菜单33"];    MenuEven[1] = ["url11","url12","url13"];
        MenuEven[2] = ["url21","url22"];
        MenuEven[3] = ["url31","url32","url33"];
    //初始化一个oPopup对象var  oPopup = window.createPopup();//这两个是获得表格绝对位置的方法,很有用的说
    function getLeftIE(x,m) {
      var dx=0;
      if (x.tagName=="TD"){
        dx=x.offsetLeft;
      }
      else if (x.tagName=="TABLE") {
        dx=x.offsetLeft;
        if (m) { dx+=(x.cellPadding!=""?parseInt(x.cellPadding):2); m=false; }
      }
      return dx+(x.parentElement.tagName=="BODY"?0:getLeftIE(x.parentElement,m));
    }
    function getTopIE(x,m) {
      var dy=0;
      if (x.tagName=="TR"){
        dy=x.offsetTop;
      }
      else if (x.tagName=="TABLE") {
        dy=x.offsetTop;
        if (m) { dy+=(x.cellPadding!=""?parseInt(x.cellPadding):2); m=false; }
      }
      return dy+(x.parentElement.tagName=="BODY"?0:getTopIE(x.parentElement,m));
    }//显示菜单
    function ButtonClick(node,t)
    {   alert("123");
       //首先得到鼠标所在的表格的位置
        var left = getLeftIE(node,true)-8;  
        var top = getTopIE(node,true);
    //定义打开的oPopup的宽度,高度
        var width = 90;
        var height = MenuText[t].length*20;  
       // var width = 400;
       // var height = 100; 
    //清空oPopup的内容,否则每次调用都只会在后面接着写
        oPopup.document.body.innerHTML = "";
    var b=document.getElementById("table1").innerHTML.toString();
    //alert(b);
    //alert(document.getElementById("table1").innerText.toString());
    var c=document.getElementById("table1").innerText.toString();
        var oPopBody = oPopup.document.body;
        oPopup.show(left,top, width, height, document.body);      
            oPopup.document.open;
    //让oPopup在鼠标离开时自动隐藏。
            oPopup.document.write("<body leftmargin=0 topmargin=0 scroll=no style='border : 0 px;bgColor:#cccccc' onmouseover=clearTimeout(parent.popt); onmouseout=parent.popt=setTimeout('parent.oPopup.hide()',10);>");//用document.write()写菜单内容
            oPopup.document.write("<table width=100%  height=100% style='border-collapse : collapse;'>");
        for(var i=0;i<MenuText[t].length;i++)
            {
            oPopup.document.write("<tr><td background='image/topbg.gif' bgcolor=#cccccc style='border-top : #cccccc 1px solid;border-bottom : #666666 1px solid;border-left : #cccccc 1px solid;border-right : #666666 1px solid;mouse : hand; font-size : 12px; color:#000000;text-align : left;vertical-align : center;CURSOR: hand' onmouseover=this.bgColor='#C2D2E5'; onmouseout=this.bgColor='#cccccc'; height='20' onclick='parent.parent.main.location.href=\""+MenuEven[t][i]+"\"';>"+MenuText[t][i]+"</td></tr>");
            }
            oPopup.document.write("</table></td></tr></table>");
    //alert("nnnnn")
            //oPopup.document.write("<table>");
     //oPopup.document.write(b);
     //oPopup.document.write("<tr><td>3333</td></tr>");
      //oPopup.document.write("</table>");
    // alert("mmmm")
            oPopup.document.write("</body>")
    }</script>
    </HEAD><BODY>
    <table>
    <tr>
    <td align="left" onclick="ButtonClick(this,1)">菜单1</td>
    </tr>
    <br>
    <tr>
    <td height="200">
    </td>
    </tr>
    <br>
    </table>
    <table id="table1">
    <tr>
    <td align="left" >菜单3</td>
    </tr>
    <br>
    <tr>
    <td align="left" style="color:red" >菜单4</td>
    <br></BODY>
    </HTML>
      

  2.   

    DOM做这种动态伸展是比较方便的办法.