HTML text box input letter auto Capitalization

Source: Internet
Author: User

method One : use JS, add the OnKeyUp method to the HTML tag, use JS to capitalize the characters

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8" />        <title></title>        <Script>            functionToUpper () {vartext=document.getElementById ("ToUpper"). Value;            alert (text); }        </Script>    </Head>    <Body>input Box:<inputtype= "text"ID= "ToUpper"onblur= "ToUpper ()"onkeyup= "This.value=this.value.touppercase ()" />    </Body></HTML>
Enter ASD and the input box will be automatically converted to asd! Remove cursor Eject ASD

method Two : use CSS by using CSS in tags

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8" />        <title></title>        <Script>            functionToUpper () {vartext=document.getElementById ("ToUpper"). Value;            alert (text); }        </Script>    </Head>    <Body>input Box:<inputtype= "text"ID= "ToUpper"onblur= "ToUpper ()"style= "text-transform:uppercase;" />    </Body></HTML>
Enter ASD and the input box will be automatically converted to asd! Remove cursor Eject ASD

the value of the Text-transform is -none: Default, no conversion occurs, capitalize: The first letter of each word is capitalized; uppercase: uppercase conversion; lowercase: lowercase conversion

the difference between the two : When the method is used, it will give the user a sense of conversion; Method two interface is shown in uppercase, but in essence CSS style, the background needs to be capitalized

HTML text box input letter auto Capitalization

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.