应该模糊还是mousedown火? [英] Should blur or mousedown fire first?

查看:105
本文介绍了应该模糊还是mousedown火?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!doctype html>
<body>
<input onblur="alert('b');">
<button onmousedown="alert('m');">a</button>
</body>

由于某种原因,模糊似乎首先在FF / IE上触发(但是mousedown似乎首先触发了Chrome / Safari)。

For some reason blur seems to fire first on FF / IE (but mousedown seems to fire first for Chrome / Safari).

然而,当我们将代码更改为:

Yet when we change the code to this:

<!doctype html>
<body>
<input onblur="document.title+='b';">
<button onmousedown="document.title+='m';">a</button>
</body>

现在由于某种原因,mousedown似乎首先针对所有浏览器。

Now for some reason mousedown seems to fire first for all browsers.

1)这种异常的解释可能是什么?

1) What may be the explanation for this abnormality?

2)根据W3C规范,应该是标准行为?

2) Based on W3C specs, which should be the standard behavior?

推荐答案

所以对于这个测试我做了这个小提琴

So for this test I made this fiddle

<input onblur="document.getElementById('msg').innerHTML+=new Date().getTime()+' - blur<br/>'">
<button onmousedown="document.getElementById('msg').innerHTML+=new Date().getTime()+' - md<br/>'">a</button>
<div id="msg">---<br/></div>

在Windows XPsp3中,在Fx5,IE8,Opera 11,Safari5,Chrome 13中,首先是mousedown ,

On Windows XPsp3, in Fx5, IE8, Opera 11, Safari5, Chrome 13 it is ALL mousedown first, blur after

更新:使用警报时除外。如果你在某个地方发出警报,你不能指望任何想要他们的方式。

UPDATE: EXCEPT when you use alert. You cannot count on anything working the way you want them to if you put an alert somewhere.

例如,一些(较旧的)浏览器将进入一个永无止境的循环,如果你警告一个错误onblur,然后尝试集中的违规字段,然后将模糊空的下一个字段

For example some (older) browsers would go into a never ending loop if you alerted an error onblur and then tried to focus the offending field, which would then blur the empty next field

这篇关于应该模糊还是mousedown火?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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