獲取樣式:
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,