<!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 runat="server">
    <title>无标题页</title>
    <script language=javascript>
    var Pane = new Array();
    
   function ShowMenu()
   {
    var pantmp = document.createElement("DIV");
    if(Pane.length==0)
    {
    pantmp.id = "1";
    }else
    {
    pantmp.id = Pane.length+1;
    }
    
     var x, y, w, h, ox, oy;
 
 x = event.clientX;
 y = event.clientY;
  
 pantmp.style.posLeft = x + document.body.scrollLeft;
 pantmp.style.posTop = y + document.body.scrollTop;
    
    pantmp.style.background= "red";
    pantmp.style.width=100;
    pantmp.style.height=20;
    pantmp.style.visibility = "visible";
    pantmp.innerHTML="a"+pantmp.id;
    document.body.appendChild(pantmp);
    document.getElementById("1").style.left="200";
    document.getElementById("1").style.top = "440";
    if(Pane.length==0)
    {
    Pane[0] = pantmp;
    }else
    {
     Pane[Pane.length] = pantmp;
    }
    return false;
   }
   
     document.oncontextmenu = ShowMenu
    </script>
</head>
<body>
    <form id="form1">
    <div id=rightmenu style="visibility:hidden; ">
    dasf
    </div>
    </form>
</body>
</html>现在能够动态创建,但是不能够在鼠标右键的位置显示,请大家帮帮忙,急。谢谢。

解决方案 »

  1.   

    <!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 runat="server">
        <title>无标题页</title>
        <script language=javascript>
        var Pane = new Array();
        
       function ShowMenu()
       {
        var pantmp = document.createElement("DIV");
        pantmp.style.position = "absolute";
        if(Pane.length==0)
        {
        pantmp.id = "1";
        }else
        {
        pantmp.id = Pane.length+1;
        }
        
         var x, y, w, h, ox, oy;
     
     x = event.clientX;
     y = event.clientY;
      
     pantmp.style.posLeft = x + document.body.scrollLeft;
     pantmp.style.posTop = y + document.body.scrollTop;
        
        pantmp.style.background= "red";
        pantmp.style.width=100;
        pantmp.style.height=20;
        pantmp.style.visibility = "visible";
        pantmp.innerHTML="a"+pantmp.id;
        document.body.appendChild(pantmp);
        document.getElementById("1").style.left="200";
        document.getElementById("1").style.top = "440";
        if(Pane.length==0)
        {
        Pane[0] = pantmp;
        }else
        {
         Pane[Pane.length] = pantmp;
        }
        return false;
       }
       
         document.oncontextmenu = ShowMenu
        </script>
    </head>
    <body>
        <form id="form1">
        <div id=rightmenu style="visibility:hidden; ">
        dasf
        </div>
        </form>
    </body>
    </html>
    这样做
      

  2.   

    <HTML>
    <HEAD>
    <TITLE>鼠标右键将不起作用!!!</TITLE>
    <script language="JavaScript1.2"> 
    if (window.Event) 
    document.captureEvents(Event.MOUSEUP); function nocontextmenu()  
    {
    Layer1.style.left = event.clientX + document.body.scrollLeft;
    Layer1.style.top = event.clientY + document.body.scrollTop;
    Layer1.style.visibility = "visible";
    event.cancelBubble = true;
    event.returnValue = false;
    return false;
    }function norightclick(e)
    {
    if (window.Event)
    {
    if (e.which == 2 || e.which == 3)
    return false;
    }
    else
    if (event.button == 2 || event.button == 3)
    {
    event.cancelBubble = true
    event.returnValue = false;
    return false;
    }
    else
    if(event.button==1)
    {
    if(event.srcElement.nodeName=="BODY")
    if(Layer1.style.visibility == "visible")
    Layer1.style.visibility="hidden";
    }
    }document.oncontextmenu = nocontextmenu;
    document.onmousedown = norightclick;
    </script>
    </HEAD><BODY BGCOLOR="#FFFFFF">
    <div id="Layer1" style="position:absolute; left:0px; top:0px; width:73px; height:73px; z-index:1; visibility: hidden"> 
      <table border="1" cellspacing="1" cellpadding="1" width="100%" bordercolor="#999999">
        <tr>
          <td align="center"><a href="../tt.htm">菜单一</a></td>
        </tr>
        <tr>
          <td align="center">菜单二</td>
        </tr>
        <tr>
          <td align="center">菜单三</td>
        </tr>
        <tr>
          <td align="center">菜单四</td>
        </tr>
      </table>
    </div>
    鼠标右键将不起作用!!
    </BODY>
    </HTML>
      

  3.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <script language="javascript" type="text/javascript">
     var mx;
     var my;
      function mouseCoords(ev){ 
     if(ev.pageX || ev.pageY){ 
      return {x:ev.pageX, y:ev.pageY}; 
     } 
     return { 
      x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
      y:ev.clientY + document.body.scrollTop  - document.body.clientTop 
     }; 

    document.onmousedown = mouseDown; 
     function mouseDown(ev){
     ev   = ev || window.event; 
       var s=mouseCoords(ev);
     mx= s.x;my=s.y;
      var div = document.getElementById("1");
      div.style.top=my.toString()+"px";
          div.style.left=mx.toString()+"px";
      div.style.visibility="visible";
         }
         function hidden(k){
        
            document.getElementById("1").style.visibility="hidden";
          
         }</script>
    你在页面点击试试
    <div style="POSITION: absolute; visibility: hidden" id="1"><table width="400" height="250" border="1" cellspacing="0" bordercolor="#3333CC" bgcolor="#9999FF">
      <tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table></div>
    </body>
    </html>
      

  4.   

    你把上面的拷贝到 html文件中 看看是不是你要的效果