在js中有的朋友用xx.style.top取不到对象的值,很是郁闷。原因就在与style只能内嵌样式的值。 也就是说要这么写才能获取到值:

   <div ></div>

  下面是参考:

    var divTop =divObj.style.top   //style仅内嵌样式得到内嵌样式的属性值
    var divTop = divObj.currentStyle.top  //仅微软IE支持currentStyle,火狐谷歌不支持

    //getComputedStyle() --DOM提供的方法,火狐、谷歌、IE9支持
    var divTop = document.defaultView.getComputedStyle(divObj, null).top;  

 

其实也可以用:offsetLeft获取的 

   如:

    xx.offsetLeft;  //xx代表对象

 

详情请看我的另一篇随笔:http://www.cnblogs.com/clouds008/archive/2012/05/17/2506861.html ()

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-03-07
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2022-01-02
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案