str = str.substring(0,1).toUpperCase()+str.substring(1)
截取第一个位置变成大写,然后从第一个位置截取所有。
<script type="text/javascript">alert("hello world".replace(/(^|\s+)\w/g,function(s){
return s.toUpperCase()
}))
</script>
str = str.substring(0,1).toUpperCase()+str.substring(1)
截取第一个位置变成大写,然后从第一个位置截取所有。
<script type="text/javascript">alert("hello world".replace(/(^|\s+)\w/g,function(s){
return s.toUpperCase()
}))
</script>