zoukankan      html  css  js  c++  java
  • js 操作css

    类似于jquery的css()函数,js封装

    CSS函数:css(oDiv , “width” , “200px ”)设置样式
    css(oDiv , “width”)获取样式

    JS:
    Function css(){
        If(arguments.length==2){
            Return arguments[0].style[arguments[1]]; //获取样式
       }else{
            Arguments[0].style[arguments[1]] = arguments[2]; //设置样式
       }
    }
    或是
    Function css(obj,name,vaule){
        If(arguments.length==2){
            Return obj.style[name]; //获取样式
        }else{
            obj.style[name] = vaule; //设置样式
        }
    }

    调用:
    Window.onload= function(){
        Var oDiv = document.getElementById(“div1”);
       css(oDiv , “width” , “200px ”);
        css(oDiv , “background” , “blue ”);
    }

    but:

    Obj.style: 只能操作行间样式
    兼容IE和高版本chrome操作非行间样式:obj.currentStyle
    兼容chrome,FF,IE9操作非行间样式:obj.getComputedStyle(oDiv , null )

    If(oDIv .currentStyle){
    oDiv.currentStyle.width = “”;
    }else{
    getComputedStyle(oDiv,false).width= “”;
    }

  • 相关阅读:
    .net core
    asp.net core之abp框架
    C#
    c#
    C#
    C#
    C#
    技术术语
    mysql
    006.内测.情景之迷你财务记账
  • 原文地址:https://www.cnblogs.com/jlliu/p/5319076.html
Copyright © 2011-2022 走看看