How can I capitalize the first letter of an input?

后端 未结 4 758
执念已碎
执念已碎 2021-01-17 23:35

I\'m currently trying to capitalize the very first letter from an input.

Here\'s what I tryed :

fieldset input
{
    text-transform:capitalize;
}


        
相关标签:
4条回答
  • 2021-01-17 23:51

    You must use

    <fieldset>
                <legend>DATA...</legend>
                <input type="text" class="inputName" placeholder="Введите имя">
    

    without <input />

    then in CSS:

    fieldset input {
        text-transform: capitalize;
    }
    
    0 讨论(0)
  • 2021-01-17 23:58

    Impossible. It is possible with Javascript, or by putting only the first word within a span.

    0 讨论(0)
  • 2021-01-18 00:03
    $('#INPUT_ID').keyup(function(){
        if($(this).val().length>0 && $(this).val().length<5){
            $(this).val($(this).val().charAt(0).toUpperCase()+$(this).val().substr(1));
         }
    });
    

    Can't use length==1, as it doesn't work if user types fast.

    0 讨论(0)
  • 2021-01-18 00:05

    JS: str.charAt(0).toUpperCase();

    0 讨论(0)
提交回复
热议问题