用正则的方法操作转驼峰

var str2 = 'border-bottom-color';

function test(str2){
    var re = /(-)(w)/g;
    return str2.replace(re, function($0, $1,$2){
        // console.log($0 + ':' + $2)
        return $2.toUpperCase();
    });
}

alert(test(str2));

$0代表整个。$1代表第一组,$2 代表第二个

原文地址:https://www.cnblogs.com/fuxiang-yang/p/4967088.html