input loses focus and gets focus
When the mouse clicks in the search box, the text disappears.
We often use the search box to get focus and lose focus when we do the site, because lazy, every time to write very annoying, so that once and for all, encounter similar situation to call the OK
Related JS code:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>input lose focus and gain focus jquery Focus Event Plugin-lazy people build stations </title>
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type= "Text/javascript" ></ Script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
Focusblur
Jquery.focusblur = function (focusid) {
var Focusblurid = $ (FOCUSID);
var defval = Focusblurid.val ();
Focusblurid.focus (function () {
var Thisval = $ (this). Val ();
if (thisval==defval) {
$ (this). Val ("");
}
});
Focusblurid.blur (function () {
var Thisval = $ (this). Val ();
if (thisval== "") {
$ (this). Val (Defval);
}
});
};
/* Below is the call method * *
$.focusblur ("#searchkey");
});
</script>
<body>
<form action= "" method= "POST" >
<input name= "" type= "text" value= "input search keyword" id= "Searchkey"/>
<input name= "" type= "Submit" id= "searchbtn" value= "Search"/>
</form>
<p>input loses focus and gets focus jquery Focus event plugin, <br/><strong style= "color: #F00" > Mouse clicks in the search box when the text disappears </ Strong>. </p>
</body>
jquery gets and loses focus events
Copy Code code as follows:
<script src= "jquery-1.9.1.js" type= "Text/javascript" ></script >
<script type= "Text/javascript" >
$ (function () {
$ (' #username '). focus (function ()//time when the classroom is triggered
{
$ (' #username '). Val (');
})
$ (' #username '). Blur (The time that is triggered when the function () loses focus
{
if ($ (' #username '). val () = = ' Marry ') {
$ (' #q ') . Text (' Username already exists! ')
}
Else {$ (' #q '). Text (' ok! ')}
})