zoukankan      html  css  js  c++  java
  • js操作css样式、js的兼容问题

    一、js操作css样式

     div . style . width="200px"  在div标签内我们添加了一个style属性,并设定width值。这种写法会给标签带来大量的style属性,跟实际项目是不符,我们没有让css和html分离

     所以如果是为了获取css样式

      window . getcomputedstyle()

      获取经过计算机的所有属性

      getcomputed style 参数

        第一个参数是当前元素,第二个一般写null ; 并且这个方法是只读的(只能读取,不能修改)

        IE6—8不支持这个写法,Ie的用currentstyle

    二、js的兼容方法

      1、||(或)

        var   dd=document . documentElement . clienWidth || document . body . clientWidth

      2、if()else { }

        if (window . getcomputedstyle){

          csss=window . getcomputedstyle(aa . null)

          }else{

            csss=aa . currentstyle

            }

          console . log(csss)

      3、try { }  cath (err){ }

        var   csss;

          try {

            csss=window . getcomputedstyle (aa . null)

          }  cath (err){
            csss=aa . currentstyle

            }

        不报错,执行try里面的代码块,报错执行cath里面的代码块;前提是条件是报错,如果不是报错,就不用使用

        这必须是在报错的前提下,和if  else  比较性能上比较差,不在万不得已的情况下不使用

  • 相关阅读:
    Linux基础命令-cp
    Linux基础命令-mkdir
    Linux基础命令-touch
    Linux基础命令-diff
    Linux基础命令-cut
    Linux基础命令-stat
    System.Web.HttpException: 请求在此上下文中不可用
    数据库日志删除、压缩操作
    如何收缩和删除SQL日志文件
    Excel 常用宏代码大全
  • 原文地址:https://www.cnblogs.com/yanghuiting/p/10039381.html
Copyright © 2011-2022 走看看