Javascript text box color changes when clicked

Source: Internet
Author: User

Javascript text box color changes when clicked

The default text box on the Web page is always gray, and it seems a little impatient. You all like to use CSS and JS to change its style. Today, I wrote a text box that changes the color of the clicked border, when you click the text box to be entered, the text box is automatically highlighted and highlighted, with visual effects, making the text box much more beautiful. The HTML code is as follows:

. Code
  1. The border color changes when the input box is clicked.
  2. <Script type = "text/javascript">
  3. // FocusClass: The style when the focus is obtained
  4. // NormalClass: normal style
  5. Function focusInput (focusClass, normalClass ){
  6. Var elements = document. getElementsByTagName ("input ");
  7. For (var I = 0; I <elements. length; I ++ ){
  8. If (elements [I]. type! = "Button" & elements [I]. type! = "Submit" & elements [I]. type! = "Reset "){
  9. Elements [I]. onfocus = function () {this. className = focusClass ;};
  10. Elements [I]. onblur = function () {this. className = normalClass | '';};
  11. }
  12. }
  13. }
  14. </Script>
  15. <Script type = "text/javascript">
  16. Window. onload = function (){
  17. FocusInput ('focusinput', 'normalinput ');
  18. }
  19. </Script>
  20. Enter the name:
  21. It works in Firefox, but Firefox and chrome. By default, these two browsers will automatically input a box to add the click effect, so sometimes they cannot see clearly, and IE is outstanding. Front-end framework example

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.