我想使用JavaScript触发鼠标中键事件。是否可以使用Javascript触发鼠标中键?
我想要它,因为它正在粘贴剪贴板中的最后一个选定对象。
谢谢,吉米
有相同的问题,做了很多挖掘,这就是我最终使用的:
if ( window.CustomEvent ) {
var middleClick = new MouseEvent( "click", { "button": 1, "which": 2 });
jQuery(".selector")[0].dispatchEvent( middleClick );
}
您可以使用
以标识单击了哪个鼠标按钮。
返回指示改变状态的按钮的整数值。
* 0 for standard 'click', usually left button
* 1 for middle button, usually wheel-click
* 2 for right button, usually right-click
Note that this convention is not followed in Internet Explorer: see
QuirksMode for details.
根据定点设备的配置,按钮的顺序可能会有所不同。
也阅读
Which mouse button has been clicked?
有两个属性可用于查找哪个鼠标按钮已经单击:哪个和按钮。请注意这些属性并不总是处理点击事件。为了安全检测您必须使用的鼠标按钮mousedown或mouseup事件。