• 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>
  • 相关阅读:
    Vue组件之间传值
    Vue 调试工具
    组件注册
    组件化思想
    图书列表案例
    数组相关API
    Vue常用特性
    选项卡案例
    Vue模板语法
    案例选项卡
  • 原文地址:https://www.cnblogs.com/ygm125/p/2108142.html
Copyright © 2020-2023  润新知