在Javascript中大写输入文本 [英] Capitalize input text in Javascript

查看:67
本文介绍了在Javascript中大写输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单中,我有两个按钮可将文本转换为大写和小写。我使用此函数将输入文本转换为大写:

In a form, I have two buttons to transform text to uppercase and lowercase. I am using this function to transform input text to upper case:

document.xyz.textinput.value=document.xyz.textinput.value.toUpperCase()

现在,我想添加一个新按钮来大写每个单词。是否可以使用以下代码实现此目的?

Now, I want to add a new button to capitalize each word. Is it possible to achieve this with the following code?

document.xyz.textinput.value=document.xyz.textinput.value.capitalize()

谢谢

推荐答案

试试这个:

document.xyz.textinput.value = document.xyz.textinput.charAt(0).toUpperCase() + document.xyz.textinput.slice(1);

如果你想要大写函数,请看这里

If you want a capitalize functions, See here.

这篇关于在Javascript中大写输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆