代码如下: <html> <head> <title>层的绝对定位</title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <script type="text/javascript"> <!-- function setPosition(obj) { document.getElementById("Layer1").style.display = "block"; document.getElementById("Layer1").style.top = obj.offsetParent.offsetTop + 18; document.getElementById("Layer1").style.left = obj.offsetParent.offsetLeft + 45; } function setPosition1(obj) { document.getElementById("Layer1").style.display = "block"; document.getElementById("Layer1").style.top = obj.offsetTop + 18; document.getElementById("Layer1").style.left = obj.offsetLeft + 45; } function HiddenDiv() { document.getElementById("Layer1").style.display = "none"; } //--> </script> </head> <body> <div id="Layer1" style="position:absolute; display:none;"> <table border="1"> <tr> <td>fasdasdfasdf</td> <td>adfasdsd</td> </tr> <tr> <td>fasdasdfasdf</td> <td>adfasdsd</td> </tr> </table></div> <table> <tr> <td><a href="javascript:" οnmοuseοver='javascript:setPosition(this);' οnmοuseοut="javascript:HiddenDiv();">Click</a></td> </tr> <tr> <td><a href="javascript:" οnmοuseοver='javascript:setPosition(this);' οnmοuseοut="javascript:HiddenDiv();">Click</a></td> </tr> <tr> <td><a href="javascript:" οnmοuseοver='javascript:setPosition(this);' οnmοuseοut="javascript:HiddenDiv();">Click</a></td> </tr> </table> <div> <a href="javascript:" οnmοuseοver='javascript:setPosition1(this);' οnmοuseοut="javascript:HiddenDiv();">Click It</a> <br /> <a href="javascript:" οnmοuseοver='javascript:setPosition1(this);' οnmοuseοut="javascript:HiddenDiv();">Click It</a> <br /> <a href="javascript:" οnmοuseοver='javascript:setPosition1(this);' οnmοuseοut="javascript:HiddenDiv();">Click It</a> <br /> </div> </body> </html>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]