将字符串(border-bottom-color)转成驼峰(borderBottomColor)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>请写一个字符串转成驼峰的方法</title>
</head>
<body>
<script> /* * 问题描述: * 请写一个字符串转成驼峰的方法? * border-bottom-color -> borderBottomColor * 要求:分别用字符串和正则来操作 * */ var a = 'border-bottom-color'; /* * 第一种:字符串操作 * */ (function (a) { // 将字符串通过'-'分解为数组 var arr = a.split('-'); // 遍历数组,从第2个元素开始 for ( var i = 1; i < arr.length; i++ ) { arr[i] = arr[i].substring(0,1).toUpperCase() + arr[i].substring(1); } console.log(arr.join('')); })(a); /* * 第二种:正则解法 * */ /*(function (a) { var re = /-(\w)/g; var res = a.replace(re,function ($0,$1) { return $1.toUpperCase(); }); alert(res); })(a);*/ </script>
</body>
</html>

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) &lt;script ...