Last active
December 31, 2015 03:09
-
-
Save zhoumengkang/7925999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="{:THEME_PUBLIC_URL}/js/jquery.js"></script> | |
<form action="{:U('news/Index/doJoin')}" method="post" name="join"> | |
<input type="text" name="username" id="username" ><span class="username"></span> | |
<input type="email" name="email" id="email"><span class="email"></span> | |
<input type="text" name="company" id="company"><span class="company"></span> | |
<input type="text" name="job" id="job"><span class="job"></span> | |
<input type="text" name="tel" id="tel"><span class="tel"></span> | |
<input type="text" name="qq" id="qq"><span class="qq"></span> | |
<input type="text" name="weixin" id="weixin"> | |
<input type="text" name="verify" id="verify"><img src="__ROOT__/public/captcha.php" id="verifyimg" alt="{:L('PUBLIC_CHANGE_ONE')}" style="vertical-align:middle;padding:0 5px 0 0" onclick="changeverify()"/></div> | |
<div class="form-row"> | |
<a href="javascript:void(0)" onclick="totalCheck();" class="btn-green-big" style="margin:20px 0 0"><span>报名</span></a> | |
<input type="submit" style='display:none'> | |
</div> | |
</form> | |
<script type="text/javascript"> | |
function changeverify(){ | |
var date = new Date(); | |
var ttime = date.getTime(); | |
var url = "__ROOT__/public/captcha.php"; | |
$('#verifyimg').attr('src',url+'?'+ttime); | |
}; | |
function emailCheck (email){ | |
$.post("<php>echo U('news/Index/emailCheck')</php>",{email:email},function(data){ | |
if(!parseInt(data)){ | |
$(".email").html('<div class="ok"></div>'); | |
}else{ | |
$(".email").html('<div class="error">邮箱被占用</div>'); | |
} | |
}); | |
} | |
function totalCheck(){ | |
if($('#username').val().length == 0) { | |
$(".username").html('<div class="error">请输入姓名</div>'); | |
return false; | |
} | |
if($('#company').val().length == 0) { | |
$(".company").html('<div class="error">公司信息不能为空</div>'); | |
return false; | |
} | |
if($('#job').val().length == 0) { | |
$(".job").html('<div class="error">职位信息为空</div>'); | |
return false; | |
} | |
if($("#email").val().length == 0){ | |
$(".email").html('<div class="error">邮箱不能为空</div>'); | |
return false; | |
} | |
if(!$("#email").val().match(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/)){ | |
$(".email").html('<div class="error">邮箱格式不正确</div>'); | |
return false; | |
}else{ | |
emailCheck($("#email").val()); | |
} | |
if ($('#tel').val().length == 0) { | |
$(".tel").html('<div class="error">电话不能为空</div>'); | |
return false; | |
}else{ | |
if(!$('#tel').val().match(/^1\d{10}$/)) { | |
$(".tel").html('<div class="error">请输入电话号码</div>'); | |
return false; | |
} | |
} | |
document.join.submit(); | |
} | |
$(function() { | |
$('#username').blur(function(){ | |
if($('#username').val().length == 0) { | |
$(".username").html('<div class="error">请输入姓名</div>'); | |
}else{ | |
$(".username").html('<div class="ok"></div>'); | |
} | |
}) | |
$('#company').blur(function(){ | |
if($('#company').val().length == 0) { | |
$(".company").html('<div class="error">公司信息不能为空</div>'); | |
}else{ | |
$(".company").html('<div class="ok"></div>'); | |
} | |
}) | |
$('#job').blur(function(){ | |
if($('#job').val().length == 0) { | |
$(".job").html('<div class="error">职位信息为空</div>'); | |
}else{ | |
$(".job").html('<div class="ok"></div>'); | |
} | |
}) | |
$("#email").blur(function(){ | |
if($("#email").val().length == 0){ | |
$(".email").html('<div class="error">邮箱不能为空</div>'); | |
} | |
if(!$("#email").val().match(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/)){ | |
$(".email").html('<div class="error">邮箱格式不正确</div>'); | |
}else{ | |
emailCheck($("#email").val()); | |
} | |
}) | |
$('#tel').blur(function(){ | |
if ($('#tel').val().length == 0) { | |
$(".tel").html('<div class="error">电话不能为空</div>'); | |
}else{ | |
if(!$('#tel').val().match(/^1\d{10}$/)) { | |
$(".tel").html('<div class="error">请输入电话号码</div>'); | |
}else{ | |
$(".tel").html('<div class="ok"></div>'); | |
} | |
} | |
}) | |
$('#qq').blur(function(){ | |
if(!$('#qq').val().match(/^\d{5,12}$/)) { | |
$(".qq").html('<div class="error">请输入有效的QQ号</div>'); | |
}else{ | |
$(".qq").html('<div class="ok"></div>'); | |
} | |
}) | |
$(this).bind('keydown', function(e) { | |
var key = e.which; | |
if(key == 13) { | |
totalCheck(); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
每个验证都写了两次,没有办法精简呢?