event.preventDefault是否取消了更改事件? [英] Is event.preventDefault cancelling change events?

查看:95
本文介绍了event.preventDefault是否取消了更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有某种情况我想为自己澄清,如果有人对这个问题有任何经验并愿意向我解释,我会很高兴。

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.

我的textarea有一个更改事件处理程序:

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();
});

此处理程序是否也会取消 blur 和<如果用户用鼠标点击它,code>更改 textarea的事件?如果它会,我怎么能防止这种情况发生?

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?

更新:谢谢你的回答,我不能说我试过了它,但我有类似的情况,我试图排除为什么更改没有在我的textarea上触发的可能性。在我的情况下有一个更改处理程序,如果我点击所有点击事件的区域,该处理程序不起作用默认情况下会被阻止并替换为自定义行为。

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.

这篇关于event.preventDefault是否取消了更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆