Explanation of javascript English letter case-insensitive Conversion

Source: Internet
Author: User

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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.