Input prompt information

Source: Internet
Author: User

1.input Hint HTML:
1 <spanclass= "Input_tips">2    <inputname= "Accout"type= "text"class= "Login_input login_name"value="" />3       <Divstyle= "position:relative; color: #ccc">4           <Divclass= "Tips_content"style= "Position:absolute; top:-45px; left:70 px ">User name</Div>5       </Div>6 </span>

Js:
1$ (". Input_tips"). Click (function(){2$( This). Children ("div"). CSS ("display", "none");3$( This). Children ("input"). focus ();//Sometimes when you click on a div, there's no such line .4$( This). Children ("input"). Focus (function(){//When You use the tab switch5$( This). Next ("div"). CSS ("display", "none");6     });7$( This). Children ("input"). Blur (function(){8         if(($( This). val ()) = = "") {9$( This). Next ("div"). CSS ("Display", "block");Ten         } One     }) A});

-----------------------------------Split Line 2014.12.17----------------------------------found above code in BUG:JS only if each input's Click event is triggered, the corresponding Input focus, Blur event will be registered before it will be triggered, change to the following code is OK:
1$ (". Input_tips"). Children ("input"). Focus (function(){//When You use the tab switch2$ ( This). Next ("Div"). CSS ("display", "none") ;3 });4$ (". Input_tips"). Children ("input"). Blur (function(){5     if(( $( This). Val ()) = = "" ) {6$ ( This). Next ("Div"). CSS ("Display", "block" );7     }8 });9$ (". Input_tips"). Click (function(){Ten$( This). Children ("div"). CSS ("display", "none") ; One$ ( This). Children ("input"). focus ();//Sometimes when you click on a div, there's no such line . A});

In the first case, the focus event is placed in the Click event, and the focus event corresponding to input will be bound only if none of the input's Click events trigger execution, so the bug appears when I click The first input, followed by the tab switch, the following focus event of input is not bound, it is not the implementation of the focus event, Blur event. Summary: These two fragment codes prove that jquery events are bound (registered) before they are triggered.

Input prompt information

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.