Is event.preventDefault cancelling change events?
I have a certain situation I want to clarify for myself, and I would be glad if anyone has any experience with this issue and is willing to explain it to me.
I have a textarea that has a change
event handler:
textarea.bind('change', function(event){
// do something
});
Hypothetically, what if I have some sort of开发者_Python百科 a click event handler that catches all user clicks:
$(document).bind('click', function(event){
event.preventDefault();
});
Will this handler also cancel blur
and change
events for a textarea if a user clicks out of it with his mouse? And if it will, how can I prevent this from happening?
Update: Thank you for your answers, I can not say that I tried it, but I have a similar situation and I am trying to rule out possibilities why change
is not firing on my textarea. In my case there is a change
handler that doesn't work if I click on an area in which all click
events are prevented by default and replaced with custom behaviour.
No, it will only prevent the default browser behavior for the 'click' event.
No, it won't.
Hypothetically, what if you just tried it? (answer: it won't, as stated just before me)
If you don't want users to be able to leave a inputfield (which sounds like strange user interaction to me), you might be able to just set focus after a blur
/change
event - perhaps you would need a small timeout to let the event finish first. I would not recommend it, but it's always worth a try.
精彩评论