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


<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;
}

页面加载进来文本框中显示默认值
[img]http://dl.iteye.com/upload/attachment/0080/1886/4a336ca1-ccea-3874-9d74-be2c16f1525d.png[/img]
输入错误提示信息在文本框上显示
[img]http://dl.iteye.com/upload/attachment/0080/1888/f57a8e8d-f20e-3fc8-bab5-baaa0be29db5.png[/img]
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值