Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm calling a function, that builds a table which includes several links.

I want to check if a link has been clicked with right or left mouse.

I tried to add the following part to the <a> hyperlink.

onmousedown="function mouseDown(e){
switch (e.which) {
   case 1: alert('left'); break;
   case 2: alert('middle'); break;
   case 3: alert('right'); break; }
}"

But nothing happens If I click on a link.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

The html:

<a href="#" onmousedown="mouseDown(event);">aaa</a>???????????????????????????

The javascript:

function mouseDown(e) {
  e = e || window.event;
  switch (e.which) {
    case 1: alert('left'); break;
    case 2: alert('middle'); break;
    case 3: alert('right'); break; 
  }
}?

The demo.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...