实现Web页面上的右键快捷菜单[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 erickson 的 blog

实现web页面上的右键快捷菜单

样式代码:

<style type="text/css">
   body{font: 9pt "宋体"; margintop: 0px ; color: red; background: #ffffff}
   a.{ font: 9pt "宋体"; cursor: hand; font-size: 9pt ; color: blue; text-decoration: none }
   a:active{ font: 9pt "宋体"; cursor: hand; color: #ff0033 }
   a.cc:hover{ font: 9pt "宋体"; cursor: hand; color: #ff0033}
   .box{ font: 9pt "宋体"; position: absolute; background: lightgrey; }
  </style>

html代码如下:

  <table id="itemopen" class="box" style="display:none">
   <tr>
    <td>弹出菜单</td>
   </tr>
   <tr>
    <td><a href="
http://blog.csdn.net/erickson/" class="cc">erickson的专栏</a></td>
   </tr>
   <tr>
    <td><a href="
http://www.csdn.net" class="cc">csdn</a></td>
   </tr>
   <tr>
    <td><a href="
http://www.google.com" class="cc">google 搜索</a></td>
   </tr>
   <tr>
    <td><a href="
http://www.sohu.com" class="cc">搜狐</a></td>
   </tr>
   <tr>
    <td><a href="
http://www.yahoo.com" class="cc">yahoo</a></td>
   </tr>
   <tr>
    <td><a href="
http://www.163.com" class="cc">163 网站</a></td>
   </tr>
   <tr>
    <td><a href="
http://sports.sina.com.cn" class="cc">新浪网体育</a></td>
   </tr>
 
  </table>

脚本代码:

右击鼠标显示快捷菜单:
  <script language="javascript">
   document.onmousedown = function popup() {
    menu = document.all.itemopen
    if (event.button == 2) {
    newx = window.event.x + document.body.scrollleft
    newy = window.event.y + document.body.scrolltop
    menu.style.display = ""
    menu.style.pixelleft = newx
    menu.style.pixeltop = newy
    }
    else if (event.button == 1)
    {
     menu.style.display = "none"
    }
   }
  </script>

本文关键:实现Web页面上的右键快捷菜单
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top