最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】js中大写字符串的首字母

JS crifan 1476浏览
希望在输入框中,输入字符串后,保存时,自动大写首字母。
js string capitalize first letter
How do I make the first letter of a string uppercase in JavaScript? – Stack Overflow
javascript – How to capitalize first letter of each word, like a 2-word city? – Stack Overflow
javascript – Capitalize first letter of each word in JS – Stack Overflow
【总结】
最后用:
1
2
3
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}
调用:
1
2
3
4
      if (filteredNewItem.contentOrName) {
        filteredNewItem.contentOrName = filteredNewItem.contentOrName.capitalize()
        console.log("filteredNewItem.contentOrName=", filteredNewItem.contentOrName)
      }
输出:
1
2
"hello" -> 
"Hello"

转载请注明:在路上 » 【已解决】js中大写字符串的首字母

82 queries in 0.799 seconds, using 19.08MB memory