zoukankan      html  css  js  c++  java
  • javascript 获取元素计算后的样式及删除style中指定的样式属性

    <style>
            #mytest
            {
                 100px;
                height: 100px;
                border: 1px solid blue;
            }
    </style>
    <div id="mytest" style="color: red; border: 1px solid red;"></div>
    <script type="text/javascript">// <![CDATA[
        var div = document.getElementById("mytest");
    
        var currentStyle = null;
        try {
            //获取不到综合属性的值,如border,想获取要拆分
            currentStyle = document.defaultView.getComputedStyle(div, null);
        } catch (e) {
            currentStyle = div.currentStyle; //兼容IE
        }
    
        alert(currentStyle.width); //100px
    
        try {
            div.style.removeProperty("border");
        } catch (e) {
           //IE下删除,不包括IE9 
           div.style.cssText = div.style.cssText.replace(/(border[^;]+;)|(border[^;]+)/ig, "");
        }
    
        alert(div.style.cssText); //color:red;
    // ]]></script>
  • 相关阅读:
    LCT
    Knights0.
    Beautiful Sequence
    Mole and Abandoned Mine
    防御准备
    最小生成树计数
    Miners
    朝暮(枚举基准 容斥)
    Dynamic Rankings(整体二分)
    BZOJ 3875 Ahoi2014 骑士游戏
  • 原文地址:https://www.cnblogs.com/ygm125/p/2108142.html
Copyright © 2011-2022 走看看