Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

js 写一个字符串转成驼峰的方法

$
0
0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>字符串替换</title>
<script type="text/javascript">
	window.onload = function(){
		var str='border-bottom-color';
		// String.prototype.transform = function(){
		// 	var arr = this.split('-');
		// 	for(var i=1;i<arr.length;i++){
		// 		arr[i]=arr[i].charAt(0).toUpperCase()+arr[i].substring(1);
		// 	}
		// 	return arr.join('')
		// }
		// alert(str.transform()); 面向对象加普通string方法
		//面向对象加正则表达方式
		String.prototype.transform = function(){
			var re=/-(\w)/g;
			return this.replace(re,function(){
				var args=arguments;
				return args[1].toUpperCase();
			})
		}
		alert(str.transform()); 
		
	}
</script>
</head>
<body>
    <h3>写一个字符串转成驼峰的方法?<br/>
	例如 border-bottom-color->borderBottomColor
    </h3>
</body>
</html>

作者:aspwzmuma 发表于2013-6-21 10:45:55 原文链接
阅读:44 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles