先放到表格里,再将layerTop和layerLeft设为相对表格格子的值

解决方案 »

  1.   

    对啊,我是这么写的:
    <td width="">
    <script language="JavaScript">
    <!--
     var layerTop=20;       
     var layerLeft=20;      
     var layerWidth=202;    
     var titleHeight=20;  
     .....
    </scritp>
    </td>
    可是最终出现的位置还是以页面边框为标准的位置上。
      

  2.   

    楼上两位说的对,你必须把它设为相对值,试试下面这个
    <body>
    <div id="Layer1" style="position:absolute; left:88px; top:32px; width:250px; height:200px; z-index:1; background-color: #999999; layer-background-color: #999999; border: 1px none #000000;">
    <div id="Layer2" style="position:absolute; left:0px; top:0px; width:100px; height:100px; z-index:2; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;">
    </div>
    </div>
    <input type="button" value="点我" onclick=chg();>
    </body>
    <script language="JavaScript">
    function chg()
    {
     var layerTop=20;       
     var layerLeft=20;      
     var layerWidth=20;    
     var titleHeight=20; 
     document.all.Layer2.style.top = layerTop;
     document.all.Layer2.style.left = layerLeft;
     document.all.Layer2.style.width = layerWidth;
     document.all.Layer2.style.height = titleHeight;
     }
    </script>
      

  3.   

    谢谢各位的帮忙,由于我对js是一窍不通,所以用上面老大的方法笨手笨脚的试了半天,也还是不行。我现在着急用,不得不麻烦个为了!我的页面布局是这样的:
    <html>
    <head><title></title></head>
    <body>
    <table width="760" height="100%" border="1"  bordercolor="#ffffff">
       <tr bordercolor="#333333">
        <td height="180" colspan="3" valign="top">****</td>
       </tr>
       <tr bordercolor="#333333"> 
        <td height="20" colspan="3" valign="top">***</td>
       </tr>
        
        <tr bordercolor="#333333"> 
          <td width="349" valign="top">***</td>
    /*这里我想插入的js程序是一个导航栏。本来用的是一种笨方法,将js程序用了一个html文件保存,然后在下面用了<IFRAME>包含此页面。结果各位是知道的,一点击连接页面就出现<iframe></iframe>中了。*/      <td width="202" valign="top">我想将JS程序插到这个位置</td>
      
          <td width="209" valign="top">****</td>
        </tr>
     </table>
     </body>
     </html>请问再此页面,怎么让js程序准确的定位到我想的位置?谢谢了。加分!
      

  4.   


    <td width="202" valign="top">
    <script language="JavaScript">
    我想将JS程序插到这个位置
    </script>
    </td>是这样地意思吗?
      

  5.   

    <html>
    <head>
    <title>misi</title>
    <style type="text/css">
    .titleStyle{
    background-color:#4c4c4c;color:#ffffff;border-top:1px solid #5a5a5a;font-size:9pt;cursor:hand;
    }
    .contentStyle{
    background-color:#74c000;color:#ffffff;font-size:9pt;
    }a{
    color:#ffffff;
    }
    body{
    font-size:9pt;
    }
    </style>
    </head>
    <body><script language="JavaScript">
    <!--
     var layerTop=0;       //菜单顶边距
     var layerLeft=0;      //菜单左边距
     var layerWidth=190;    //菜单总宽
     var titleHeight=20;    //标题栏高度
     var contentHeight=200; //内容区高度
     var stepNo=10;         //移动步数,数值越大移动越慢 var itemNo=0;runtimes=0;
     document.write('<span id=itemsLayer style="position:absolute;overflow:hidden;border:1px solid #707070;left:'+layerLeft+';top:'+layerTop+';width:'+layerWidth+';">'); function addItem(itemTitle,itemContent){
       itemHTML='<div id=item'+itemNo+' itemIndex='+itemNo+' style="position:relative;left:0;top:'+(-contentHeight*itemNo)+';width:'+layerWidth+';"><table width=100% cellspacing="0" cellpadding="0">'+
           '<tr><td height='+titleHeight+' onclick=changeItem('+itemNo+') class="titleStyle" align=center>'+itemTitle+'</td></tr>'+
           '<tr><td height='+contentHeight+' class="contentStyle">'+itemContent+'</td></tr></table></div>';
       document.write(itemHTML);
       itemNo++;
     }
        //添加菜单标题和内容,可任意多项,注意格式:
     addItem('嘉临门','<center><a href="#">公司介绍</a> <BR><BR><a href="#">经营理念</a><BR><BR><a href="#">经营范围</a><br><br><a href="#">店铺招商</a></center>');
     addItem('咪嘻涮涮锅','<center><a href="#">涮涮锅介绍 </a> <BR><BR><a href="#">咪嘻涮涮锅</a> <BR><BR><a href="#">配送中心</a> <BR><BR><a href="#">店面介绍</a></center>');
     addItem('咪嘻分店','<center><a href="#">十里堡华堂店</a> <BR><BR><a href="#">东安店</a> <BR><BR><a href="#">华辰店</a> <BR><BR><a href="#">华威店</a></center>');
     addItem('咪嘻加盟','<center><a href="#">加盟简章</a> <BR><BR><a href="#">加盟流程</a> <BR><BR><a href="#">成功案例</a></center>');
     addItem('信息发布','<br><center>关于咪嘻涮涮锅的最新信息!</center>');
     addItem('人力资源','<center><a href="#">员工队伍</a><br><br><a href="#">招贤纳士</a></center>'); document.write('</span>')
     document.all.itemsLayer.style.height=itemNo*titleHeight+contentHeight; toItemIndex=itemNo-1;onItemIndex=itemNo-1; function changeItem(clickItemIndex){
       <a href="jialinmen.php"></a>
       toItemIndex=clickItemIndex;
       if(toItemIndex-onItemIndex>0) moveUp(); else moveDown();
       runtimes++;
       if(runtimes>=stepNo){
         onItemIndex=toItemIndex;
         runtimes=0;}
       else
         setTimeout("changeItem(toItemIndex)",10);
     } function moveUp(){
       for(i=onItemIndex+1;i<=toItemIndex;i++)
         eval('document.all.item'+i+'.style.top=parseInt(document.all.item'+i+'.style.top)-contentHeight/stepNo;');
     } function moveDown(){
       for(i=onItemIndex;i>toItemIndex;i--)
         eval('document.all.item'+i+'.style.top=parseInt(document.all.item'+i+'.style.top)+contentHeight/stepNo;');
     }
     changeItem(0);
    //-->
    </script>
    </body>
    </html>
    这是我要插入的导航栏,下载下去可以直接运行的。麻烦各位可以下来看看。我就是想把这个导航栏放在<td width="202" valign="top"></td>中。该怎样插入。实在是着急,麻烦各位了!
      

  6.   

    就是定位的问题
    你可以先用DW标尺功能,把鼠标移到你的TD里的然后看坐标是多少
    再把layerLeft和layerTop设成相应的值.
    不行就一点点调,
    笨方法,
      

  7.   

    试试用 <IFRAME> 做导航栏