This article describes the method of js to determine which mouse left, middle, and right click is clicked. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows: <html>
<head>
<title>js determines which mouse left, middle, and right click is clicked - Ke Leyi</title>
<script type="text/javascript">
function whichButton(event)
{
var btnNum = event.button;
if (btnNum==2)
{
alert("You clicked the right mouse button!")
}
else if(btnNum==0)
{
alert("You clicked the left mouse button!")
}
else if(btnNum==1)
{
alert("You clicked the middle mouse button!");
}
else
{
alert("You clicked" + btnNum+ "sign key, I can't determine its name.");
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<p>Please click the mouse in the document. A message box will prompt which mouse button you clicked. </p>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.