zoukankan      html  css  js  c++  java
  • 获取非行间样式

    获取非行间样式

    原理:

      IE: obj.currentStyle[属性名]

      谷歌:getComputedStyle(obj, false)[属性名]

    代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>获取非行内样式</title>
        <style>
            div {
                 300px;
                height: 200px;
                background: blue;
            }
        </style>
        <script>
      // 获取非行间样式的方法: function getstyle ( obj, val ) { if ( obj.currentStyle ) { return obj.currentStyle[val] } else { return getComputedStyle(obj,false)[val] } } window.onload = function () { var box = document.getElementsByTagName('div')[0]; box.onclick = function () { alert( getstyle(box,'height') ) } } </script> </head> <body> <div></div> </body> </html>
  • 相关阅读:
    poj2240
    poj1135
    poj1062
    poj3278
    2218 补丁vs错误
    必做: 1041、1024、1077、2218、1183(较难)
    poj2828
    poj3253
    洛谷P1122 最大子树和
    1074 食物链
  • 原文地址:https://www.cnblogs.com/wangyihong/p/6658290.html
Copyright © 2011-2022 走看看