3.开始jQuery编码
利用正则表达式检测input的内容是否是email地址:
- function isEmail(email) {
- // 利用正则表达式匹配
- var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
- return regex.test(email);
- }
- function completeInviteForm() {
- setTimeout(function() {
- $("#completeform").fadeOut(400, function(){
- $(this).before('<span class="msg">All set! We will be in
- touch.</span>');
- });
- }, 1100);
- }
4.form的发送处理
- var erdiv = $("#error");
- var btnwrap = $("#btnwrap");
- $(document).ready(function(){
- $("#sendbtn").live("click", function(e){
- // 点击发送按钮触发的事件
- e.preventDefault();// 禁用submit按钮的默认动作
- var emailval = $("#email").val();
- if(!isEmail(emailval)) {//错误的Emial
- erdiv.html("enter a full e-mail address!");
- erdiv.css("display", "block");
- }
- if(isEmail(emailval)) { // 正确的Email
- erdiv.css("color", "#719dc8");
- erdiv.html("just a sec...");
- btnwrap.html('<img src="img/loader.gif" alt="loading">');
- completeInviteForm();
- }
- });
- });
