JavaScript to achieve the first letter capitalize summary

Source: Internet
Author: User
Tags continue lowercase

JavaScript to achieve the first letter capitalize summary

This article summed up several can achieve the English first letter uppercase JavaScript script, and attach a CSS implementation method, very simple and practical, here recommended to you, the need for small partners can refer to.

Method One:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 function Replacestr (str) {//Regular str = Str.tolowercase (); var reg =/b (w) |s (w)/g;//b judge boundary S to Judge Space return Str.replace (Reg,fun Ction (m) {return m.touppercase ()}); function ReplaceStr1 (str) {str = str.tolowercase (); var strtemp = ""; New string for (Var i=0;i<str.length;i++) {if (i = = 0) {strtemp + = Str[i].touppercase ();//first continue;} if (Str[i] = "" & amp;& i< str.length-1) {//space after strtemp + = ""; strtemp + + str[i+1].touppercase (); i++; Continue } strtemp + = Str[i]; return strtemp; var text = "ABCD abcd efgh"; Console.log (Replacestr (text));//ABCD ABCD efgh console.log (text) replaceStr1 ABCD//ABCD

Method Two:

?

1 2 3 4 5 6 7 8 9 10 11 <script type= "Textjavascript" > Function Ucfirst (str) {var str = str.tolowercase (); var strarr = Str.split ('); var result = '; for (var i-strarr) {result = Strarr[i].substring (0,1). toUpperCase () +strarr[i].substring (1) + ';} return result; } </script>

Method Three:

?

1 2 3 4 5 6 7 8 <script type= "Textjavascript" > Function Ucfirst (str) {var str = str.tolowercase (); str = str.replace (/bw+b/g, funct Ion (Word) {return word.substring (0,1). toUpperCase () +word.substring (1);}); return str; </script>

CSS to achieve:

?

1 2 3 4 5 6 7 8 9 10 11 12 13-14
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.