zoukankan      html  css  js  c++  java
  • style和getComputedStyle(ff)和currentStyle

    obj.style:这个方法只能JS只能获取写在html标签中的写在style属性中的值(style=”…”),而无法获取定义在<style type="text/css">里面的属性。

    IE中使用的是obj.currentStyle方法,而FF是用的是getComputedStyle 方法 

    <style type=”text/css”>
    <!–
    .ss{color:#cdcdcd;}
    –>
    </style>
    </head>

    <body>
    <div id=”css88″ class=”ss” style=”200px; height:200px; background:#333333″>JS获取CSS属性值</div>
    <script type=”text/javascript”>
    alert(document.getElementById(“css88″).style.width);//200px
    alert(document.getElementById(“css88″).style.color);//空白
    </script>
    </body> 

    #myDiv {
    background-color:blue;
    100px;
    height:200px;
    }
    </style>
    <body>
    <div id ="myDiv" style=" border:1px solid black"></div>
    <script>
    var myDiv = document.getElementById("myDiv");
    var computedStyle = document.defaultView.getComputedStyle(myDiv, null);
    alert(computedStyle.backgroundColor); //"red"
    alert(computedStyle.width); //"100px"
    alert(computedStyle.height); //"200px"
    alert(computedStyle.border); //在某些浏览器中是“1px solid black”
    </script

    <span style="font-family:Arial;font-size:14px;">var myDiv = document.getElementById("myDiv");
    var computedStyle = myDiv.currentStyle;
    alert(computedStyle.backgroundColor); //"red"
    alert(computedStyle.width); //"100px"
    alert(computedStyle.height); //"200px"
    alert(computedStyle.border); //undefined</span> 

  • 相关阅读:
    Kinect学习笔记(六)——深度数据测量技术及应用
    [device]/proc/devices and /dev/
    [Eth]Mac/Phy/mdio/Rgmii
    [uboot]uboot如何引导系统
    [网络]Linux一些网络知识
    [基础]sizeof和strlen
    [基础]关于extern指针和数组的用法
    [ucos]了解ucos
    [Linux]gcc/libc/glibc
    [i.MX6q]i.MX6q处理器,linux操作系统平台搭建 从SD卡启动系统
  • 原文地址:https://www.cnblogs.com/lingshenghao/p/7456828.html
Copyright © 2011-2022 走看看