开发者

jQuery: How to stop the change() event from firing from the blur() handler?

开发者 https://www.devze.com 2022-12-20 12:19 出处:网络
I have the following scenario: $(\"#element\").blur(validate).change(onElementChange); The validate() function should prevent the change event from firing, if the value of the #element is not valid

I have the following scenario:

$("#element").blur(validate).change(onElementChange);

The validate() function should prevent the change event from firing, if the value of the #element is not valid. I cannot add the validate to change, because it needs to 开发者_开发百科validate on blur too. If add the validate() to both events, the alert with the validation error will pop up twice.

So, the my question is, can I stop the change event from firing from the handler of the blur event?

Also if you have a different solution (without using plugins), i would like to hear it.

Thanks


I've found a workaround to the problem:

  • handling the validation only after the change event
  • triggering the change event in the handler or the blur (in case)


can't you call the onElementChange function inside your validate function when it returns valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号