This article will introduce jquery's implementation of input click to hide text code. The principle is simple. We only need to use the focus and blur events to solve the problem. For more information, see the reference.
Javascript implementation
| The Code is as follows: |
Copy code |
<Input name = "s" value = "Search" class = "size4of5" type = "text" onfocus = "if (this. value = 'search') this. value = ''" onblur = "if (this. value = '') this. value = 'search' "> |
JQuery Implementation Method
| The Code is as follows: |
Copy code |
<Input name = "search" value = "Search" class = "size4of5" type = "text"> <Script> $ (Function (){ $ ("Input [name = search]"). focus (function (){ If (smf (this). val () = "Search "){ Smf (this). val (""); } }); $ ("Input [name = search]"). blur (function (){ If (smf (this). val () = ""){ Smf (this). val ("Search "); } }); }); </Script> |