JavaScript when the text box gets the focus setting border:
This section describes how to set the border style of a text box after the focus of the text box is a very simple question, but it is possible that the front-desk artist is not too familiar with JavaScript, so it is a simple example to introduce, so that the needs of friends to expand.
The code is as follows:
<!DOCTYPE HTML> <HTML> <Head> <MetaCharSet= "Utf-8"> <Head><title>text box gets focus border color-ant tribe</title><styletype= "Text/css">ul{List-style:None;margin:50px;}. MyTest{Border:1px solid Red;}</style><Scripttype= "Text/javascript">window.onload=function(){ varusername=document.getElementById ("username"); varPW=document.getElementById ("PW"); Username.onfocus=function(){ This. Style.border="1px solid Red"; } Username.onblur=function(){ This. Style.border=""; } Pw.onfocus=function(){ This. ClassName="mytest"; } Pw.onblur=function(){ This. ClassName=""; }}</Script><Body><ul> <Li>Name:<inputtype= "text"ID= "username" /></Li> <Li>Password:<inputtype= "Password"ID= "PW" /></Li></ul></Body></HTML>
The above code implements our requirements, when the mouse is placed in the text box, you can achieve the text box color, leaving the time to return to the original. Under
A simple introduction to the implementation principle:
The text box is bound to the event handler, and when the text box gets focus, the style of the border is set with style or classname, and the style is emptied when the text box loses focus. The above use style and classname to set the text box properties, is to let the reader know more about the content, I hope to help you.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8315
For more information, refer to: http://www.softwhy.com/javascript/
JavaScript when text box gets focus set border