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

posted @ 2018-11-29 16:00  黑太阳-  阅读(95)  评论(0编辑  收藏  举报