熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

實現Web頁面上的右鍵快捷菜單

2022-06-13   來源: JSP教程 

  樣式代碼

  <style type=text/css>
   body{font: pt 宋體; margintop: px ; color: red; background: #ffffff}
   a{ font: pt 宋體; cursor: hand; fontsize: pt ; color: blue; textdecoration: none }
   a:active{ font: pt 宋體; cursor: hand; color: #FF }
   :hover{ font: pt 宋體; cursor: hand; color: #FF}
   box{ font: pt 宋體; position: absolute; background: LightGrey; }
  </style>

  html代碼如下

  <table id=itemopen class=box >
   <tr>
    <td>彈出菜單</td>
   </tr>
   <tr>
    <td><a cc>Erickson的專欄</a></td>
   </tr>
   <tr>
    <td><a cc>CSDN</a></td>
   </tr>
   <tr>
    <td><a cc>Google 搜索</a></td>
   </tr>
   <tr>
    <td><a cc>搜狐</a></td>
   </tr>
   <tr>
    <td><a cc>Yahoo</a></td>
   </tr>
   <tr>
    <td><a cc> 網站</a></td>
   </tr>
   <tr>
    <td><a cc>新浪網體育</a></td>
   </tr>
   </table>

  腳本代碼

  右擊鼠標顯示快捷菜單
  <script language=JavaScript>
   documentonmousedown = function popUp() {
    menu = emopen
    if (eventbutton == ) {
    newX = windoweventx + documentbodyscrollLeft
    newY = windoweventy + documentbodyscrollTop
    menustyledisplay =
    menustylepixelLeft = newX
    menustylepixelTop = newY
    }
    else if (eventbutton == )
    {
     menustyledisplay = none
    }
   }
  </script>

  屏蔽IE默認的WinForm快捷菜單
  <script language=JavaScript>
   var message=;
   function clickIE()
   {
    if (documentall)
    {
     (message);
     return false;
    }
   }
   function clickNS(e)
   {
    if (documentlayers||(documentgetElementById&&!documentall))
    {
     if (ewhich==)
     {
      newX = windoweventx + documentbodyscrollLeft
      newY = windoweventy + documentbodyscrollTop
      menu = emopen
      if ( menustyledisplay == )
      {
       menustyledisplay = none
      }
      else
      {
       menustyledisplay =
      }
      menustylepixelLeft = newX
      menustylepixelTop = newY
     }
     if (ewhich==)
     {
      (message);
      return false;
     }
    }
   }
   if (documentlayers)
   {
    documentcaptureEvents(EventMOUSEDOWN);
    documentonmousedown=clickNS;
   }
   else
   {
    documentonmouseup=clickNS;documentoncontextmenu=clickIE;
   }
   documentoncontextmenu=new Function(return false)
  </script>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19776.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.