为什么在同一元素上的mouseDown事件触发后不点击事件触发? [英] Why doesn't click event fire after mouseDown event on same element fires?

查看:80
本文介绍了为什么在同一元素上的mouseDown事件触发后不点击事件触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个元素上有一个mouseDown事件和一个click事件。当我点击它时,mouseDown事件触发(即警告鼠标按下P),但点击事件不会。但是,如果我注释掉mouseDown警告语句,则click事件会显示其警报。为什么是这样? http://jsfiddle.net/A8vhq/

I have a mouseDown event and a click event on the same element. When I click on it, the mouseDown event fires (i.e. alerts "Mouse pressed on P"), but the click event doesn't. However, if I comment out the mouseDown alert statement, the click event does display its alert. Why is this? http://jsfiddle.net/A8vhq/

推荐答案

这是因为点击永远不会发生,当出现警告框时,它会中断元素上的mouseup事件,从而中断鼠标点击。

That's because the click never happens, when the alert box appears it interrupts the mouseup event on the element, thus interrupting mouseclick.

使用 console.log('message')来测试代码,而不是 alert

use console.log('message') to test your code instead of alert.

这篇关于为什么在同一元素上的mouseDown事件触发后不点击事件触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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