在safari中,右键点击时好像关注上下文菜单,所以上下文菜单接收mouseup事件而不是P元素。至于解决方案,您可以检测鼠标按钮,以防止其右键单击。除非你想处理自定义上下文菜单,否则右键单击事件是凌乱的 。
如果你想MouseUp事件时,用鼠标右键单击射击在Safari工作,你将需要通过添加这个属性P元素禁用上下文菜单:
oncontextmenu="return false">
它也有可能检测是否单击左侧的触发事件(这通常是要处理的按钮):
function mouse_handler(event) {
var evt=window.event||event;
var button = evt.which || evt.button;
if (button == 1) { // if left mouse button
// handle the event
}
}
在从W3Schools的例子中,这会导致这样的事情:
function myFunction(elmnt,clr,event)
{
var evt=window.event||event;
var button = evt.which || evt.button;
if (button == 1) { // if left mouse button
elmnt.style.color=clr;
}
}
然后通过该事件在函数调用:
<p onmousedown="myFunction(this,'red',event)" onmouseup="myFunction(this,'green',event)">
哦,不。抱歉。你误会了我。我不想禁用onmouseup和onmousedown右键单击。我想触发Safari浏览器的onmouseup – Cyril 2013-04-25 06:55:11
您想让它处理右键单击的原因是否有原因? – 2013-04-25 06:56:08
我用一种处理方式更新了我的答案 – 2013-04-25 07:05:30