当页面信息填写不完整,点击提交后,直接跳转到未填写位置

<li>
  <span><em>*</em>联系人邮箱</span>
  <input class="input_mail input" name="email[]" required id="cyf_input_mail" type="text" placeholder="邮箱" />
  <u class="spa spa14"></u>
</li>

<input class="input2" type="button" id="submit1"  value="提交" />
/**失焦提示**/
$(function(){
  $(".input").blur(function(){
    $(".spa").css("color","#ff0000")
    if($(this).is("#cyf_input_mail")){
         var cyf_input_mail=$("#cyf_input_mail").val();
          var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
          if(cyf_input_mail == undefined || cyf_input_mail == "") {
            $(".spa11").text("请填写联系人邮箱");
        $(this).css("border","1px solid #ff0000")
          }else if(!reg.test(cyf_input_mail)){
              $(".spa11").text("请填写真实有效的邮箱地址");
          }else{
              $(".spa11").text("");
              $(this).css("border","1px solid #dbdbdb")
          }
       }
  })
})
/**聚焦提示**/
$(".input").focus(function(){
  if($(this).is("#cyf_input_mail")){
    $(".spa11").text("请填写真实有效的常用邮箱地址").css("color","#aaa")
      $(this).css("border","1px solid #aaa")
   }
})
/**提交判断**/
function checked(){
  reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   if($("#cyf_input_mail").val()==""){
     $(".spa14").text('请填写联系人邮箱');
      $("#cyf_input_mail").focus();
      $(".spa").css("color","#ff0000");
      return false;
   }else if(!reg.test($("#cyf_input_mail").val())){
     $(".spa14").text("请填写真实有效的邮箱地址");
      $("#cyf_input_mail").focus();
      $(".spa").css("color","#ff0000");
      return false;
    } else{
       $(".spa14").text('');
    }
    return true;
}
$("#submit1").click(function(){
  $(".spa").css("color","#ff0000");
   $(".input").css("border","1px solid ff0000");
    if(checked()){
      $("#cyf_form").submit();
    }
})

猜你喜欢

转载自www.cnblogs.com/zhangjianzhen/p/9844980.html