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

时间:2010-03-26 17:41:10  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: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; }  </st...
  正文:

样式代码

<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>

屏蔽IE默认的WinForm快捷菜单:
  <script language="JavaScript">
   var message="";
   function clickIE()
   {
    if (document.all)
    {
     (message);
     return false;
    }
   }
   function clickNS(e)
   {
    if (document.layers||(document.getElementById&&!document.all))
    {
     if (e.which==2)
     {
      newX = window.event.x + document.body.scrollLeft
      newY = window.event.y + document.body.scrollTop

"实现Web页面上的右键快捷菜单"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/JavaScript/13360.html


关键字:

关于《实现Web页面上的右键快捷菜单》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td