The simplest I've found an example using JS onblur
The onblur event is the event that occurs when the cursor loses focus.
Cases
1.html
| The code is as follows |
Copy Code |
<input type=text name=text1 value= "1111onblur_green" onblur= "(document.bgcolor= ' green ')" > <input type=text name=text2 value= "2222onblur_black" onblur= "(document.bgcolor= ' black ')" > <input type=text name=text2 value= "3333onblur_yellow" onblur= "(document.bgcolor= ' yellow ')" > |
The above is written directly in HTML input, we can be defined as a function
| The code is as follows |
Copy Code |
<script> function Onblurs () { if (frm.name.value== "") { Alert ("Please enter your name!") "); }else if (frm.funny.value== "") { Alert ("Hobby must not be empty!") "); } } </script> <form name= "frm" > <tr> <td> Your name:</td> <td><input type= "text" id= "name" onblur= "Onblus ()"/></td> </tr><tr> <td> Your hobby:</td> <td><input type= "text" id= "funny" onblur= "Onblus ()"/></td> </tr> </form> |
The above JS verification is almost, we use jquery blur for Ajax verification, below is my work example
Html
| The code is as follows |
Copy Code |
<input name= "Tgmo" type= "text" class= "TCINP" id= "Tgmo" size= "/>" $ (' #tgmo '). blur (function () { Alert ($ (this). Val ()); $.post (' Post.php?action=check ', {' Tgmo ': $ (this). Val ()},function (data) { alert (data); if (data==0) { $ (' #sy_a '). Show (); $ (' #autoregister '). val (1); } Else { $ (' #sy_a '). Hide (); $ (' #autoregister '). val (0); }
}); }) |
post.php
is to get the phone for verification, return the corresponding data, such as we can directly input
Echo 1;
About the jquery blur () method
On top our blur just binds the event directly through jquery, which makes it a lot easier to change its color when the input field loses focus (blur):
Definitions and usage
The Blur event occurs when the element loses focus.
The blur () function triggers the blur event, or if a function parameter is set, it can also specify the code to execute when the Blur event occurs.
Tip: Earlier, the Blur event occurred only on form elements. In a new browser, this event can be used for any element.