代码之家  ›  专栏  ›  技术社区  ›  Jonathan.

chrome、opera和IE(javascript)中的右键单击事件(onclick)

  •  3
  • Jonathan.  · 技术社区  · 14 年前

    document.onclick 不会开火。

    我想有一个img元素的自定义上下文菜单。我该怎么办?

    1 回复  |  直到 4 年前
        1
  •  7
  •   brianghig    14 年前

    下面是一些处理图像左键和右键单击的html示例。

    <html>
    <head>
        <script type="text/javascript">
            function handleRightClick() {
                alert("Got right click!");
            };
    
            function handleLeftClick() {
                alert("Got left click!");
            };
        </script
    </head>
    <body>
        <img src="http://thefuturebuzz.com/pics/the-matrix.jpg" onclick="handleLeftClick(this);" oncontextmenu="handleRightClick(this); return false;" />
    </body>
    </html>
    

    有关更多信息,请查看 http://www.w3schools.com/html5/html5_ref_eventattributes.asp