链接

 

获取样式: 

 getComputedStyle  什么是计算后的样式

 就是经过css样式组合 和 js操作后 的 最后的结果

 

设置样式有三种方法:

 
div.style.backgroundColor = "red"
 
div.style.setProperty('background-color','green')

div.style.cssText += ";background-color:red;";

 

删除相应的样式


div.style.removeProperty('background-color')

 

如何转为驼峰

'background-color'  -- >  backgroundColor

var cameLize = function(str) {


        return str.replace(/-+(.)?/g, function(match, chr) {

      //chr 就是 (.)  也就是 c, 因为前面一定有一个 -

      // 先判断chr有没有, 以免后面报错

      // match 这里是整体匹配到了 -c , 但是最后只取了子项, 并转为大写后返回 , 所以 -c 会被替换成 C


                return chr ? chr.toUpperCase() : "";

      
        });


};

 

关键正则理解

 

'/aaABBcdefH1g3Ggg'.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2');
 
 $1是AB  $2是Bc 


而不是  aaABBcdefH  和 g ,

 因为要先保证 整体能匹配, 在分配 $1 $2,