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

后端 未结 4 1545
暗喜
暗喜 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:42

    I know this question is old but the simplest way to do it would be to check event.relatedTarget. The first part of the if statement is to prevent throwing an error if relatedTarget is null (the IF will short circuit because null is equivalent to false and the browser knows that it doesn't have to check the second condition if the first condition is false in an && statement).

    So:

    if(event.relatedTarget && event.relatedTarget.type!="submit"){
         //do your animation 
    }
    

提交回复
热议问题