我使用 JQuery 1.7 来处理事件。
function objToStr(obj) {
return ...string representation of the object
}
$slider.mousedown(function(e) {
console.log("$slider.mousedown:\n" + objToStr(e) );
});
$slider.mousemove( function(e) {
console.log("$slider.mousemove:\n" + objToStr(e) );
});
结果如下:
$slider.mousedown:
altKey = false
attrChange = undefined
attrName = undefined
bubbles = true
button = 0
buttons = undefined
cancelable = true
clientX = 319
clientY = 13
ctrlKey = false
currentTarget = object
data = null
delegateTarget = object
eventPhase = 3
fromElement = undefined
handleObj = object
isDefaultPrevented = (function)
isImmediatePropagationStopped = (function)
isPropagationStopped = (function)
jQuery17209754494933906718 = true
metaKey = false
offsetX = undefined
offsetY = undefined
originalEvent = object
pageX = 319
pageY = 13
preventDefault = (function)
relatedNode = undefined
relatedTarget = null
screenX = 2876
screenY = 223
shiftKey = false
srcElement = undefined
stopImmediatePropagation = (function)
stopPropagation = (function)
target = object
timeStamp = 869699957
toElement = undefined
type = "mousedown"
view = object
which = 1
$slider.mousemove:
currentTarget = object
data = null
delegateTarget = object
exclusive = undefined
handleObj = object
isDefaultPrevented = (function)
isImmediatePropagationStopped = (function)
isPropagationStopped = (function)
isTrigger = true
jQuery17209754494933906718 = true
namespace = ""
namespace_re = null
preventDefault = (function)
result = undefined
stopImmediatePropagation = (function)
stopPropagation = (function)
target = object
timeStamp = 1334151903323
type = "mousemove"
我需要访问e.which
但mousemove
显然它没有传递给事件处理程序?
我不想使用jQuery: Detecting pressed mouse button during mousemove event 中建议的标志算法。因为如果用户将鼠标按钮拖到浏览器窗口之外并在那里释放,当鼠标回到浏览器窗口时,仍然认为它被按下了。然后我必须为鼠标离开窗口时添加处理程序并且它太多了。有没有更简单的方法可以知道在事件处理程序中按下了哪个鼠标按钮?mousemove()