This paper illustrates the hump-type and hyphen-conversion function of JS. Share to everyone for your reference, specific as follows:
On the Internet to find this paragraph, more like
1. Hump Transfer character:
VARs = "Foostylecss";
s = S.replace ([[A-z])/g, "-$1"). toLowerCase ();
Use regular to replace, concise and clear, very good
|
2. Turn Hump
vars1 = "Foo-style-css";
S1 = S1.replace (//-(/w)/g, function (all, letter) {
Returnletter.touppercase ();
});
|
It's not quite clear what this 2 looks.
So I write one, ^_^, this is easy to understand, is the code a bit more:
VARs = "Style-sheet-base";
Vara = S.split ("-");
Varo = a[0];
for (vari=1;i<a.length;i++) {
o = O + a[i].slice (0,1). toUpperCase () + a[i].slice (1);
}
|
Write another, this time with a regular:
vars1 = "Style-sheet-base";
S1 = S1.replace (//-(/w)/g, function (x) {return X.slice (1). toUpperCase ();});
|
Haha, interesting.