Convert lowercase letter to upper case in javascript

后端 未结 6 1758
温柔的废话
温柔的废话 2021-01-01 14:45

I have a code that will convert lower case letters to uppercase but it works only with IE and not in Crome or Firefox.

function ChangeToUpper()
  {         
         


        
相关标签:
6条回答
  • 2021-01-01 15:18
    <script type="text/javascript">
        function ChangeCase(elem)
        {
            elem.value = elem.value.toUpperCase();
        }
    </script>
    <input onblur="ChangeCase(this);" type="text" id="txt1" />
    

    separate javascript from your HTML

    window.onload = function(){
            var textBx = document.getElementById ( "txt1" );
    
            textBx.onblur = function() {
                this.value = this.value.toUpperCase();
            };
        };
    
    <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
    

    If the textbox is inside a naming container then use something like this

    var textBx = document.getElementById ("<%= txt1.ClientID %>");
    
                textBx.onblur = function() {
                    this.value = this.value.toUpperCase();
                };)
    
    0 讨论(0)
  • 2021-01-01 15:18

    You can simply use CSS and do text-transform:uppercase and on submit you run toUppercase(). Or you just submit as mixed and you capitalize letters on server side :)

    0 讨论(0)
  • 2021-01-01 15:19

    Have you tried .toUpperCase()?

    Links:

    • Formatting text using JavaScript
    • JAVASCRIPT toUpperCase() METHOD
    0 讨论(0)
  • 2021-01-01 15:24

    If you don't want to make an explicit JavaScript function, here you can do it in just one line:

    Convert to lower and upper case respectively:

    <asp:TextBox ID="txt1" onblur='this.value = this.value.toLowerCase();'></asp:TextBox>
    <asp:TextBox ID="txt1" onblur='this.value = this.value.toUpperCase();'></asp:TextBox>
    
    0 讨论(0)
  • 2021-01-01 15:27

    I would say the easiest way is..

    <input id="yourid" style="**text-transform: uppercase**" type="text" />
    
    0 讨论(0)
  • 2021-01-01 15:31

    Have you tried this?

    var myString = "this is a String";
    alert(myString.toUpperCase()); // "THIS IS A STRING"
    alert(myString.toLowerCase()); // "this is a string"
    

    Thanks... Hope you like it.

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