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

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

JS crifan 1030浏览 0评论
希望在输入框中,输入字符串后,保存时,自动大写首字母。
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
【总结】
最后用:
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}
调用:
      if (filteredNewItem.contentOrName) {
        filteredNewItem.contentOrName = filteredNewItem.contentOrName.capitalize()
        console.log("filteredNewItem.contentOrName=", filteredNewItem.contentOrName)
      }
输出:
"hello" -> 
"Hello"

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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.165 seconds, using 22.05MB memory