You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function test(str){
const a = str.split(" ").map(item=>item[0].toUpperCase()+item.substring(1)).join(" ")
return a
}
document.write(test("a23 b23 ccc2123 1"));
Activity
wenyejie commentedon May 27, 2019
xiangshuo1992 commentedon May 27, 2019
楼上用的没问题,学习嘛,那我就来扩展一下。
text-transform
属性控制文本的大小写,是CSS2.1的属性,兼容性问题不大。属性值是关键字,有4+1种,这个1是实验性属性值。
capitalize
这个关键字强制每个单词的首字母转换为大写。
uppercase
这个关键字强制所有字符被转换为大写。
lowercase
这个关键字强制所有字符被转换为小写。
none
这个关键字阻止所有字符的大小写被转换。
full-width (实验性属性值)
这个关键字强制字符 — 主要是表意字符和拉丁文字 — 书写进一个方形里,并允许它们按照一般的东亚文字(比如中文或日文)对齐。
除了以上,还有一些基本上不会用到的默认值等,就不多说了。
tzjoke commentedon May 28, 2019
补充楼上的:
xiangshuo1992 commentedon May 28, 2019
@tzjoke 你这个是第一行文字的第一个字母大写。
你是要补充这种用法吗?
blueRoach commentedon Jul 15, 2020
text-transform:capitalize;
smile-2008 commentedon Oct 13, 2020
.demo::first-letter {
text-transform: uppercase;
}
smile-2008 commentedon Nov 2, 2020
text-transform:capitalize;
YU-zhao-jun commentedon Nov 26, 2020
function test(str){
const a = str.split(" ").map(item=>item[0].toUpperCase()+item.substring(1)).join(" ")
return a
}
document.write(test("a23 b23 ccc2123 1"));
ttop5 commentedon Nov 30, 2020
CSLukkun commentedon Mar 12, 2021
.cap{
text-tansform:capitalize;
}