jQuery Stop .blur() event when clicking “submit” button

后端 未结 4 1472
暗喜
暗喜 2021-02-07 17:36

I am building a small landing page with a simple demo e-mail signup form. I want to have the form field open up when focused, and then shrink back down on blur.

However

4条回答
  •  忘了有多久
    2021-02-07 17:53

    why not rely on submit event instead of click? http://jsbin.com/ehujup/5/edit

    just couple changes into the html and js

    wrap inputs into the form and add required for email as it obviously suppose to be

    in js, remove handler which listen #submitbtn

    $("#submitbtn").on("click", function(e){
      e.stopImmediatePropagation();
      $("#signup").fadeOut(220);
    });
    

    and use instead submit form listerer

    $("#form").on("submit", function(e){
      $("#signup").fadeOut(220);
      return false;
    });
    

    you may use $.ajax() to make it even better.

    Doing this you gain point in terms of validation and the native browser's HTML5 validator will make check email format where it is supported.

提交回复
热议问题