Вопрос

According to the JQuery documentation, event.which is supposed to return 1 if the user was pressing the left mouse button at the time of the event.

However, the whole mouse-button-pressed logic seems to be broken for Firefox and Internet Explorer. Please see this JSFiddle that outputs the value of event.which using a mousemove event.

The JSFiddle will demonstrate that Firefox (24.0) and Internet Explorer (11.0.9600.16384) always return the value 1 whatever button you pressed or did not press.

Question time!

Am I the only one experiencing this issue and if not, is it a bug in JQuery?

Can you think of a workaround? In my application, I need to know the correct value of event.which and I need to parse that from an mousemove event handler that is attached to the window object.

Это было полезно?

Решение

I would expect event.which to work for events involving a click such as mousedown, mouseup, click, for example.

If you need this information during a mouse move, you would have to pre-record it during one of these other events and use it when you detect the move.

http://jsfiddle.net/RDNzS/

The fragility of this, as always, is if a click event happens outside of your target area (such as not even in a browser) as you won't find out about that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top