Example
The mouse in the form disappears, moves out the prompt font to display
| The code is as follows |
Copy Code |
When the focus is captured function Onfocusfun (element, Elementvalue) { if (Element.value = = Elementvalue) { Element.value = ""; } } Leave the input box to trigger the event function Onblurfun (element, Elementvalue) { if (Element.value = = "" | | Element.value.replace (/\s/g, "") = = "") {//mouse is replaced with null regardless of whether the value in the text box is empty Element.value = Elementvalue; Assign a value to a text box } } Usage: <input type= "text" class= "value=" "id=" username "name=" username "onfocus=" onfocusfun (this, ' username/mobile number ') "onblur= "Onblurfun (this, ' username/mobile number ')"/> |
Now this is a very important time for Web page optimization, we can use jquery to implement and jquery code is more concise.
| The code is as follows |
Copy Code |
<input id= "Xf_search" type= "text"/> <script type= "Text/javascript" > (function () {$ ("#xf_search"). focus (function () {(this.value== ' Please enter the name of the property ') This.value= ': false} '; $ ("#xf_search"). Blur (function () {(this.value== ')? this.value= ' Please enter the name of the property ': false}); }()); </script> |