Sample Code for style change when the text box (input) gets the focus (onfocus)

Source: Internet
Author: User

Abstract: many designers who focus on user experience want to add the style switching effect when getting focus or hovering over the text box (input. In fact, it is very simple. We only need to get the text box on the page, and add the onfocus event or other corresponding events. This article describes how to change the style when getting the focus. After understanding the principle, it is easy to implement other effects.

Many designers who focus on user experience want to add the style switching effect when getting focus or hovering over the text box (input. In fact, it is very simple. We only need to get the text box on the page, and add the onfocus event or other corresponding events. This article describes how to change the style when getting the focus. After understanding the principle, it is easy to implement other effects.
Copy codeThe Code is as follows:
Function focusInput (focusClass, normalClass ){
Var elements = document. getElementsByTagName ("input ");
For (var I = 0; I <elements. length; I ++ ){
If (elements [I]. type! = "Button" & elements [I]. type! = "Submit" & elements [I]. type! = "Reset "){
// If (elements [I]. type = "text "){
Elements [I]. onfocus = function () {this. className = focusClass ;};
Elements [I]. onblur = function () {this. className = normalClass | '';};
}
}
}

Window. onload = function (){
FocusInput ('focusinput', 'normalinput ');
}

Copy codeThe Code is as follows:
<Style type = "text/css">
. NormalInput {border: 1px solid # ccc ;}
. FocusInput {border: 1px solid # FFD42C ;}
</Style>

Related Article

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.