zoukankan      html  css  js  c++  java
  • Javascript动态操作CSS总结

    一、使用js操作css属性的写法

    1、对于没有中划线的css属性一般直接使用style.属性名即可。

    如:obj.style.marginobj.style.widthobj.style.leftobj.style.position

    2、对于含有中划线的css属性,将每个中划线去掉并将每个中划线后的第一个字符换成大写即可。

    如:obj.style.marginTopobj.style.borderLeftWidthobj.style.zIndexobj.style.fontFamily

    3js操作css float属性的特殊写法

    因为 float javascript的保留字,我们不能直接使用obj.style.float来使用,这样操作是无效的。其正确的使用方法是为:IE:obj.style.styleFloat,其他浏览器Mozilla(gecko)ff等用 styleFloat:obj.style.cssFloat

     

    二、使用js获取css属性值

    1、获取行内Styleobj.style. 属性名。<div id="css88" class="ss" style="200px; height:200px; background:#333333">JS获取CSS属性值</div> 不能访问class

    2、获取Class内及Link外部的Css属性:IE中使用的是obj.currentStyle[“属性名”]方法,而FF是用的是getComputedStyle 方法

    三、使用jscss属性赋值

    1、赋值class属性

    赋值:document.getElementById('ceil').className = "class1";

    如它有多个值:document.getElementById('ceil').className = "class1 class2 class3";

    2obj.style.cssText设定一个对象的css样式

    document.getElementById('navition').style.cssText = "您的CSS代码';

  • 相关阅读:
    第89题:格雷编码
    第88题:合并两个有序数组
    第86题:分隔链表
    第83题:删除排序链表中的重复元素
    第82题:删除排序链表中的重复元素II
    第81题:搜索旋转排序数组II
    redis笔记---不定时更新
    关于银行股
    开博客
    group by
  • 原文地址:https://www.cnblogs.com/xiaochao12345/p/4150314.html
Copyright © 2011-2022 走看看