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 |
|