<div class="codetitle"> <span><a style="CURSOR: pointer" data="34316" class="copybut" id="copybut34316" onclick="doCopy('code34316')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code34316"> <br><span style="FONT-SIZE: 18px"> <br> <br> <br><meta charset="utf-8"> <br><title>字符串替换</title> <br><script type="text/javascript"> <BR>window.onload = function(){ <BR>var str='border-bottom-color'; <BR>// String.prototype.transform = function(){ <BR>// var arr = this.split('-'); <BR>// for(var i=1;i<arr.length;i++){ <BR>// arr[i]=arr[i].charAt(0).toUpperCase()+arr[i].substring(1); <BR>// } <BR>// return arr.join('') <BR>// } <BR>// alert(str.transform()); 面向对象加普通string方法 <BR>//面向对象加正则表达方式 <BR>String.prototype.transform = function(){ <BR>var re=/-(\w)/g; <BR>return this.replace(re,function(){ <BR>var args=arguments; <BR>return args[1].toUpperCase(); <BR>}) <BR>} <BR>alert(str.transform()); <br><br>} <BR></script> <br> <br> <br><h3>写一个字符串转成驼峰的方法?<br> <br>例如 border-bottom-color->borderBottomColor <br> </h3> <br> <br></span> <br> </div>