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