With jQuery, how do I capitalize the first letter of a text field while the user is still editing that field?

后端 未结 21 2433
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 16:26

I\'m looking for an example of how to capitalize the first letter of a string being entered into a text field. Normally, this is done on the entire field with a function, r

21条回答
  •  春和景丽
    2020-11-27 16:51

    A turkish one. If someone is still interested.

     $('input[type="text"]').keyup(function() {
        $(this).val($(this).val().replace(/^([a-zA-Z\s\ö\ç\ş\ı\i\ğ\ü\Ö\Ç\Ş\İ\Ğ\Ü])|\s+([a-zA-Z\s\ö\ç\ş\ı\i\ğ\ü\Ö\Ç\Ş\İ\Ğ\Ü])/g, function ($1) {
            if ($1 == "i")
                return "İ";
            else if ($1 == " i")
                return " İ";
            return $1.toUpperCase();
        }));
    });
    

提交回复
热议问题