转化为小驼峰式

 <!--the-first-name   变成the-First-Name-->
  <!--1.先匹配-f-->
  <!--2.字符串-->
  <script type="text/javascript">
   var reg = /-(\w)/g;
   var str = "the-first-name";
//   console.log(str.replace(reg,"*"));
//   匹配多少次,function就执行多少次
   console.log(str.replace(reg,function ($,$1,$2){      //用$,$1,$2来接受
        return  $1.toUpperCase();
   }));
  </script>
  

猜你喜欢

转载自www.cnblogs.com/weixin2623670713/p/12636165.html