输入错误提示信息在文本框上显示

<label id="emailAddressDefault" for="emailAddress" style="height:27px;font-weight:normal;padding-left:8px;width:230px;background:#fff;position:absolute;top:1px;left:1px;line-height:27px;color:#a2a2a2;" onclick="$(this).hide();">订阅中大奖,请输入您的Email</label>
                	<div id="emailAddressErr" style="display:none;height:27px;font-weight:normal;padding-left:8px;width:232px;background:#fff;position:absolute;top:1px;left:1px;line-height:27px;color:red">请输入正确的E-mail地址</div>
                    <input name="emailAddress" id="emailAddress" type="text" onblur="if(!$(this).val())$('#emailAddressDefault').show();" onfocus="$('#emailAddressDefault').hide();" value=""/>
                    <a  id="submitBtn" href="javascript:void(0)" title="订阅"></a>


$(document).ready(function(){    
    $("#submitBtn").bind("click", function(){
		    if(!checkEmail($("#emailAddress").val()))
		    {		    	  
			      $("#emailAddressErr").html("请输入正确的E-mail地址");
			      $("#emailAddressErr").show('slow');
			      setTimeout(function(){
			      	$("#emailAddressErr").hide('slow');
			      	$("#emailAddress").focus();
			      },3000)			      
			      return;
		    }
		    $.ajax({
				   type: "POST",
				   async:false,
				   url: url['wcsurl'] + "SubscribeCmd?"+url['parms']+"&channel_type=2&_emailAddress="+$("#emailAddress").val()+"&_mobile="+''+"&jsoncallback=?&timeStamp=" + (new Date().getTime()),
				   dataType: "jsonp", 
				   timeout:60000,  
				   success: function(s_json){
				   					   	   
					     if(typeof s_json.result === 'undefined'){
					          $("#emailAddressErr").show('slow');
					          $("#emailAddressErr").html("系统繁忙,请稍后再试");
							      setTimeout(function(){
							      	$("#emailAddressErr").hide('slow');
							      	$("#emailAddress").focus();
							      	},3000)							      
					   	 }else{
					          $("#emailAddressErr").show('slow');
					          $("#emailAddressErr").html(s_json.result);
							      setTimeout(function(){
							      $("#emailAddressErr").hide('slow');
							      $("#emailAddress").focus();
							      	},3000)
					     }
					 },
					 error: function(s_json){
					 	  
					     if(typeof s_json.result === 'undefined'){
					          $("#emailAddressErr").show('slow');
					          $("#emailAddressErr").html("系统繁忙,请稍后再试");
							      setTimeout(function(){
							      	$("#emailAddressErr").hide('slow');
							      	$("#emailAddress").focus();
							      	},3000)
					   	 }else{
					         $("#emailAddressErr").show('slow');
					         $("#emailAddressErr").html(s_json.result);
							     setTimeout(function(){
							      	$("#emailAddressErr").hide('slow');
							      	$("#emailAddress").focus();
							      	},3000)
					     }
					 }
		    });	
		});
});

function checkEmail(email){
   re = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
   if (!re.test(email)){
     return false;
   }
   return true;
}

页面加载进来文本框中显示默认值

输入错误提示信息在文本框上显示

你可能感兴趣的:(文本框)