如果用程序触发一个网页元素的右键事件,急。。<div id="test">
</div>document.getElementById("test").click();//用程序促发click事件,那如何用程序来触发鼠标的右键事件呢?

解决方案 »

  1.   

    L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>Test Page</title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <style type="text/css">  </style>
     </head> <body><div id="divTest" style="boder: 1px solid red; background-color: blue; width: 100px; height: 100px;">
    </div> </body>
     <script type="text/javascript" defer>
     <!--
    //document.getElementById("");var div = document.getElementById("divTest");
    div.onmouseup = function() {
    if(IsRightButtonPressed()) {
    alert("Right button is pressed.");
    }
    };function IsRightButtonPressed() {
    return (event.button == 2);
    }
     //-->
     </script>
    </html>
      

  2.   

    oncontextmenu Event 
    Fires when the user clicks the right mouse button in the client area, opening the context menu.右键只有这么一个事件,似乎办不到
      

  3.   


    <html>
    <body>
    <div id="good">
    </div>
    <script>
    document.onclick = function(){
    alert();
    document.getElementById("good").contextmenu();
    }
    </script>
    </body>
    </html>
      

  4.   

    fireEvent和dispatchEventhttp://www.cnblogs.com/jailu/archive/2008/09/26/1299356.html
      

  5.   

    <html>
    <head>
    <script type="text/javascript">
    function whichElement(e)
    {
    var targ
    if (!e) var e = window.event
    if (e.target) targ = e.target
    else if (e.srcElement) targ = e.srcElement
    if (targ.nodeType == 3) // defeat Safari bug
    targ = targ.parentNode
    var tname
    tname=targ.tagName
    alert("You clicked on a " + tname + " element.")
    }
    </script>
    </head><body onmouseup="whichElement(event)"><h2>This is a header</h2>
    <p>This is a paragraph</p>
    <img border="0" src="ball16.gif" alt="Ball"></body>
    </html>
      

  6.   

    setting a property that has only a getter
    [Break on this error] event.which = 3;firebug报的这个错。
    通过一般方式自主激发怕是没戏了。