JSP页面
<html>
  <head>
    <title>标题</title>
   <link rel="stylesheet" type="text/css" href="../css/menu.css">
   <script type="text/javascript" src="../javascript/menu.js"></script>
  </head>
  <body>
  
           <div id="div1"> 
               <a href="javascript:aaa();"> hello world </a>      
           </div>  </body>
</html>CSS文件#div1{
position: absolute;
width: 100px;
height: 200px;
left: 50px;
top: 50px;
background: red;
}JS文件function aaa(){var a = document.getElementById("div1").style.left;alert(a);}请问我无法获取到a的值 怎么办?

解决方案 »

  1.   

    <html>
    <head>
    <title>??</title>
    <link rel="stylesheet" type="text/css" href="../css/menu.css">
    <script>
    function aaa(){var element = document.getElementById("div1");
    var style = element.currentStyle || document.defaultView.getComputedStyle(element, '') alert(style.left);}
    </script>
    <style>
    #div1{
    position: absolute;
    width: 100px;
    height: 200px;
    left: 50px;
    top: 50px;
    background: red;
    }
    </style>
    </head>
    <body><div id="div1"> 
    <a href="javascript:aaa();"> hello world </a> 
    </div></body>
    </html>
      

  2.   

    把css文件删除了,在html中直接写行内样式
    <div id="div1" style="position: absolute;width: 100px;height: 200px;left: 50px;top: 50px;background: red;"> 
    <a href="javascript:aaa();"> hello world </a> 
    </div>
      

  3.   

    1楼方法高端 不错  谢谢了2楼的方法我也知道...之所以不那么写 是因为CSS文件太大,全写到页面里还了得?...