以前寫過一個笨方法來獲取,ff自身就提供了一個方法(獲取自firebug)
- <html>
- <head>
- <style>
- div {
- border: 1px solid red;
- }
- #main {
- width: 400px;
- height: 300px;
- }
- #top {
- margin: 20px;
- padding: 10px;
- height: 50px;
- }
- </style>
- </head>
- <body>
- <div id="main">
- <div id="top">
- Hello
- </div>
- </div>
- </body>
- <script type="text/javascript">
- function $(id) {
- return document.getElementById(id);
- }
- function test() {
- var win = $('top').ownerDocument.defaultView;
- var style = win.getComputedStyle($('top'), "");
- var val = style.getPropertyCSSValue('margin-top').cssText;
- alert(val);
- }
- test();
- </script>
- </html>