zoukankan      html  css  js  c++  java
  • 29)

    1,JS操作css样式:

      div.style.width="100px".在div标签内我们添加了一个style属性,幷设置了width;这种写法会给标签带来大量的style属性,跟实际项目是不等的。

      window.getComPutedStyle()获取经过计算机的所有属性,就是只要渲染出来的都是经过计算的

      getComPutedStyle()  

      第一个参数是当前元素,第二个我们一般写null(并且这个是只读)

      ie6-8,不支持这个用法;ie用的是currentStyle

    2,try{ }catch error{ }

      不报错执行try里面的代码块;报错执行catch里面的代码块;前提条件是报错;不报错不能用

      var css;

      try{

        css=window.getComPutedStyle(aa,null)  

      }catch (error){

        css=aa.currentStyle

      }

    JS兼容性的写法——

      1,||

        var  w=document.documentElement.clientWidth||document.body.clientWidth

      2,if{ } else { }

        if(window.getComPutedStyle){

          css=window.getComPutedStyle(aa,null)

        }else{

          css=aa.currentStyle

        }

        console.log(css)

      3,try{ }catch error{ }

        try{

          css=window.getComPutedStyle(aa,null)  

        }catch (error){

          css=aa.currentStyle

        }

    只读;可写:

      只读,只能获取不能修改;  可写:可以修改的

    null和undefined都表示没有值:

      null,这个东西天生存在的,但是没有给值(如果我们需要清除浏览器的变量的内存需要赋值null)

        var aa=document.getElementById("aa")

        console.log(caa.parentNode.parentNode.parentNode)  //null

      undefined,这个东西压根就不存在的,人为定义的且没有赋值

        var a;   //undefined

        div.aa   //undefined

    元素节点树状图:

      document--documEntelement--body--TagName

  • 相关阅读:
    Intellij IDEA 使用spring-boot-devtools无效解决办法一
    使用docker安装myql/redis等软件
    mybatis generator插件系列--分页插件
    mybatis generator插件系列--lombok插件 (减少百分之九十bean代码)
    linux设置端口转发(一键设置)
    redis教程(The little redis book中文版)
    Redis 5种数据结构及其使用场景举例--STRING
    String中hashCode方法的线程安全
    java ShutdownHook介绍与使用
    ACM 模板库
  • 原文地址:https://www.cnblogs.com/xiaotaiyangye/p/10038895.html
Copyright © 2011-2022 走看看