只有第一个单词的大写首字母 [英] Uppercase first letter of only the first word
本文介绍了只有第一个单词的大写首字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
在JavaScript中大写字母串的第一个字母
如何将字段中第一个单词的第一个字母强制为大写?
How do you force the first letter of the first word in a field to uppercase?
推荐答案
之前被问过:< a href =https://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript>如何在JavaScript中将字符串的第一个字母设为大写?
正确答案:
function capitalizeFirstLetter(string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
您可以这样使用:
var myString = "hello world";
alert(capitalizeFirstLetter(myString));
它会提示 Hello world
这篇关于只有第一个单词的大写首字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文