javascript怎么使用字符串函数进行首字母大写

JavaScript05

javascript怎么使用字符串函数进行首字母大写,第1张

var str= "feiyongshenqing"

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>