MyException - 我的异常网
当前位置:我的异常网» Web前端 » 输入异常提示信息在文本框下显示

输入异常提示信息在文本框下显示

www.MyException.Cn  网友分享于:2013-02-20  浏览:7次
输入错误提示信息在文本框上显示
<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;
}

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

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

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有