$(function(){
$("form :input.required").each(function(){
var $required = $("
*");
//$(this).parent().append($required); //Append to the document
$(this).parent().prepend($required);
});
$('form :input').blur(function(){
var $parent = $(this).parent();
If($(this).is('#username')){
If(this.value==""||this.value.length<6){
var errorMsg = 'Please enter a username of at least 6 characters';
$parent.append('
' errorMsg '');
}else{
var okMsg = 'Correct input';
$parent.append('
' okMsg '');
If($(this).is('#email')){
if(this.value==""||(this.value!=""
&&!/. @. .[a-zA-Z]{2,4}$/.test(this.value
))){
var errorMsg = 'Please enter the correct email address';
$parent.append('
' errorMsg '');
var okMsg = 'Correct input';
$parent.append('
' okMsg '');
});
$("form :input").focus(function(){
var $parent = $(this).parent();
$parent.find(".formtips").remove();
});
$("#send").click(function(){
var $parent = $(this).parent().parent();
$parent.find(".formtips").remove();
$("form .required:input").trigger('blur');
var numError = $('form .onError').length;
If(numError){
return false;
});
$("#res").click(function(){
var $parent = $(this).parent().parent();
$parent.find(".formtips").remove();
});
});
The code is very simple and easy to understand. Friends, just take it and use it. I won’t explain it in detail here.