Next I will introduce to you how to use the toLocaleUpperCase (), toUpperCase (), toLocaleLowerCase (), and toLowerCase () functions of js to convert uppercase and lowercase letters. Next I will introduce it to you.
ToLocaleUpperCase converts all the letter characters in the string to uppercase and adapts to the current region settings in the host environment.
ToUpperCase converts all letters in the string to uppercase letters.
The Code is as follows: |
Copy code |
<Script type = "text/javascript"> Var str = "hello world! " Document. write (str. toUpperCase ()) </Script> Result Hello world! |
ToLocaleLowerCase converts all the letter characters in the string to lowercase, taking into account the current region settings of the host environment.
ToLowerCase converts the letters in the string to lowercase letters.
The usage of the above four functions is basically the same. The following uses toLowerCase as an example:
The Code is as follows: |
Copy code |
Var str = "Www. bKjia. c0m "; Document. write (str. toLowerCase (); // output www. bKjia. c0m |
We can see that toLocaleUpperCase and toUpperCase have the same functions. toLocaleLowerCase and toLowerCase have the same functions. What are their differences?
Example
The Code is as follows: |
Copy code |
<Html> <Head> <Title> case-insensitive English letter conversion </title> </Head> <Body> <Script language = "javascript"> <! -- Str = "JavaScript "; Str1 = str. toLowerCase (); Str2 = str. toUpperCase (); Document. write ("str =" + str + "<br> "); Document. write ("lower case:" + str1 + "<br> "); Document. write ("uppercase:" + str2 + "<br> "); // --> </SCRIPT> </Body> </Html>
|
(1) The toLocaleUpperCase toLocaleLowerCase functions adapt to the current region settings in the host environment when converting characters in the string. In most cases, the result is the same as that obtained by using the toUpperCase toLowerCase function. However, if the language rules conflict with the conventional Unicode case-sensitivity ing method, the results will be different.
(2) The toUpperCase toLowerCase method does not convert non-letter characters in the string.
Instance
Convert JavaScript input letters to uppercase (jQuery)
The Code is as follows: |
Copy code |
<Input type = "text" NAME = "pName" onkeypress = "keyPress ()"> <Script language = "JavaScript"> <Script> $ (Function (){ $ ('Body'). layout (); }); Function changeup () { Var keyCode = event. keyCode;
Var realkey = String. fromCharCode (keyCode). toUpperCase (); Alert (realkey ); Event. returnValue = realkey; } </Script> |