JavaScript when text box gets focus set border

Source: Internet
Author: User

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

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.