onblur vs onclick时机 [英] onblur vs onclick timing

查看:105
本文介绍了onblur vs onclick时机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个 textarea 元素,当 onblur 时,它将自身转换为 div code>事件发生在同一个 textarea 上。还有一个按钮,它的 onclick 属性设置为 function f

There is a textarea element which converts itself into a div when onblur event happens on that same textarea. There is also a button which has its onclick property set to function f.

如果有人在 textarea 中写入,然后点击按钮 f 被触发,但也触发 onblur 事件处理程序。在这种情况下是否有一些订单规则,或两个处理函数可能会以随机顺序触发?

If one is writing in the textarea and then clicks on a button, f is fired, but also onblur event handler is triggered. Is there some order rules in this case, or the two handler functions may fire in random order?

推荐答案

我在这里创建了一个jsfiddle : http://jsfiddle.net/z5SEp/

I created a jsfiddle here: http://jsfiddle.net/z5SEp/

最新Chrome的事件似乎是:

The events for latest Chrome seem to be:

mousedown
blur
mouseup
click 

尽管我找不到依赖的文档,但对我来说模糊是有意义的在mousedown之后,但在mouseup之前发射。鼠标导致模糊,但您可以将鼠标按钮长时间停留一段时间,仍会导致模糊。

Although I could not find any documentation to rely on, it would make sense to me that blur is fired after mousedown, but before mouseup. Mousedown causes blur, but you could leave your mouse button down for an extended period of time and still cause a blur.

点击事件的顺序将始终为1. mousedown 2. mouseup 3.点击。

The order of click events will always be 1. mousedown 2. mouseup 3. click. The blur makes sense to be after mousedown but before mouseup.

更多的事情要记住

如果您触发按钮,请点击: $('button')。trigger('click'); ,那么模糊事件将不会触发,焦点将保留在textarea上。

If you trigger the button click like this: $('button').trigger('click');, then the blur event will not fire, and focus will remain on the textarea.

这篇关于onblur vs onclick时机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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