Can I handle a right click event on an HTML <button /> element?

前端 未结 4 1764
孤街浪徒
孤街浪徒 2020-12-31 11:11

I\'ve seen plenty of questions and answers on SO and elsewhere that talk about right click events and how to catch and handle them with JavaScript, generally using the

4条回答
  •  死守一世寂寞
    2020-12-31 11:45

    http://jsfiddle.net/jqYN5/ is this what you are looking for? Adding context-menu:

    
    `
    
    document.getElementById('btn').onclick = function() {
      alert('click!')
    }
    
    document.getElementById('btn2').oncontextmenu = function() {
      alert('right click!')
    }
    

提交回复
热议问题