js写一个字符串转成驼峰的实例

时间:2013-06-21    点击:92   
复制代码 代码如下:

<SPAN style="FONT-SIZE: 18px"><!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></SPAN>
解析js如何获取当前url中的参数值并复制给input
Ajax异步提交表单数据的说明及方法实例
JS localStorage实现本地缓存的方法
js获取某月的最后一天日期的简单实例
js遍历、动态的添加数据的小例子
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved