onclick在前还是onblur在前?

Posted on May 14, 2008 by Fdream

想写一个Mootools的select插件,和html里的select类似的功能,不过能够完全自己定制界面,而且不会像默认控件一样永远在最高层。在实现一个功能时,当时由于思维出了点偏差,碰到一个奇怪的问题:到底是onclick事件先发生还是onblur事件先发生呢?

假设有两个div,id分别为a和b,在a上绑定onclick事件,在b上绑定onblur事件,事先通过focus()方法让光标聚焦在b上,这样,当点击a时,将分别发生onclick和onblur事件,但是,哪个会先发生呢?

特别在IE和Firefox下测试了一下,测试结果比较诡异:

在IE6下:onblur和onclick事件的发生顺序是完全随机的,有时候onblur在前,有时候onclick在前,但两者的次数差不多是相同的;

在FF2下:始终是onclick事件在前。

分享 |
Categories:
Ajax Web
Tags:
Comments:
Leave a comment
Views:
6,332 Views

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>