zoukankan      html  css  js  c++  java
  • HTML DOM-->内部样式表与外部样式表的读写

    1.获取

      IE中:

        元素节点.currentStyle.样式属性表

        元素节点.currentStyle['样式属性名']

      其他:

        window.getComputedStyle(元素节点,伪类).样式属性名

        window.getComputedStyle(元素节点,伪类)['样式属性名']

        伪类一般写null即可

      举例:点击按钮获取它的背景色

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>js_excise</title>
            <script src="./js/js_excise.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body style="height: 187.5rem;">
            <button id="in" onclick="func()" style="background-color: red;">更新</button>
            <input  type="text" name="Text" placeholder="please your name" my='abner'>
            <script type="text/javascript">
                var w = document.getElementById('in')
                function func(){
                    var c = window.getComputedStyle(w,null).backgroundColor
                    console.log(c)
                }
            </script>
        </body>
    </html>

      输出:

     2.设置样式中属性的值

      元素节点.Style.样式属性名 = 样式属性值

      举例:将按钮颜色改为绿色

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>js_excise</title>
            <script src="./js/js_excise.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body style="height: 187.5rem;">
            <button id="in" onclick="func()" style="background-color: red;">更新</button>
            <input  type="text" name="Text" placeholder="please your name" my='abner'>
            <script type="text/javascript">
                var w = document.getElementById('in')
                function func(){        
                    w.style.backgroundColor = 'green'
                    var c = window.getComputedStyle(w,null).backgroundColor
                    console.log(c)
                }
            </script>
        </body>
    </html>

      输出:

      

  • 相关阅读:
    基于windows server 2016和sqlserver 2016 AlwaysOn的群集配置
    Mysql基于Mysql Cluster+MysqlRouter的集群部署方案
    阿里云ECS部署Redis主备哨兵集群遇到的问题
    Informix数据库配置与连接
    Linux系统中Redis和Tomcat的PID文件路径设置
    Linux端口映射,80端口映射到8080端口
    Tomcat优化配置
    Tomcat配置自定义JAVA环境
    VMware虚拟机系统无法使用桥接联网
    PostgreSQL远程访问设置
  • 原文地址:https://www.cnblogs.com/abner-pan/p/12725026.html
Copyright © 2011-2022 走看看