JavaScript RegExp to CamelCase a hyphened CSS property

后端 未结 6 1200
心在旅途
心在旅途 2021-02-19 12:47

I am trying to change CSS properties like this one.

-moz-border-radius

To the JavaScript CSS property like so.

MozBorderRadius
         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 13:28

    You would be better off using a function as the second parameter in replace(), and you could also use a regex literal instead of the RegExp constructor:

    var replaced = '-moz-border-radius'.replace(/-([a-z])/gi, function(s, group1) {
        return group1.toUpperCase();
    });
    

提交回复
热议问题