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