自动将第一个字符用作大写 [英] taking first character as capital automatically

查看:53
本文介绍了自动将第一个字符用作大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在文本框中自动将第一个字符作为大写字母



i want to take the first character as capital automatically in textbox

推荐答案

如果您希望通过javascript使用它,请尝试使用此方法
If you wanted it through javascript, then try this
<script type="text/javascript" language="javascript">
    function capFirst(oTextBox) {
        oTextBox.value = oTextBox.value[0].toUpperCase() + oTextBox.value.substring(1);
               }
</script>
<asp:TextBox runat="server" onChange="javascript:capFirst(this);" ID="Tb1" AutoPostBack="False" />


private void tb1_TextChanged(object sender, EventArgs e)
        {
         tb1.Text = tb1.Text.Substring(0, 1).ToUpper() + tb1.Text.Substring(1);
            }


如果使用winforms

In case if use winforms

private void tb1_Leave(object sender, EventArgs e)
        {
         tb1.Text = tb1.Text.Substring(0, 1).ToUpper() + tb1.Text.Substring(1);
            }



如果是aspnet



Incase of aspnet

private void tb1_TextChanged(object sender, EventArgs e)
        {
         tb1.Text = tb1.Text.Substring(0, 1).ToUpper() + tb1.Text.Substring(1);
            }



不要忘记为aspx中的文本框使用Autopostback = true



Dont forget to use Autopostback=true for the textbox in aspx


这篇关于自动将第一个字符用作大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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