问题
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 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.
回答1:
No, it will only prevent the default browser behavior for the 'click' event.
回答2:
No, it won't.
回答3:
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.
来源:https://stackoverflow.com/questions/2950798/is-event-preventdefault-cancelling-change-events