onfocus and onblur Application code examples

Source: Internet
Author: User

onfocus and onblur application code examples:
These two events always feel that the application is the most frequent, although very simple, perhaps beginners are not familiar with the two, so the following examples of simple introduction of their use.
The code example is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"/><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Onblur and onfocus events-Ant Tribe</title><styletype= "Text/css">Li{Height:30px;List-style:None;font-size:12px;}Li input{width:120px;Height:15px;}</style><Scripttype= "Text/javascript">functionFocush () { This. Style.backgroundcolor="#CCC";  This. Style.color="Green";}functionBlurh () { This. Style.backgroundcolor="Red";  This. Style.color="Yellow";} Window.onload=function(){  varUserName=document.getElementById ("UserName"); varPW=document.getElementById ("PW"); Username.onfocus=Focush; Username.onblur=Blurh; Pw.onfocus=Focush; Pw.onblur=Blurh;}</Script></Head><Body><Div>  <ul>    <Li>Name:<inputtype= "text"ID= "UserName" /></Li>    <Li>Password:<inputtype= "Password"ID= "PW" /></Li>  </ul></Div></Body></HTML>

In the above code, the background color and font color can be set appropriately when the text box and password box get focus or lose focus.
About onfocus Events and onblur events there is not much to be introduced here, you can refer to the relevant reading.
Related reading:
The 1.onfocus event can be found in the Onfocus event section of JavaScript .
The 2.onblur event can be found in the Onblur event section of JavaScript .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8864

For more information, refer to: http://www.softwhy.com/javascript/

onfocus and onblur Application code examples

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.