<!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=utf-8" />
<title>自定义右键菜单</title>
<style type="text/css">
body,ul,li{
margin: 0px;
padding: 0px;
}
body{
font: 12px/24px arial;
}
#menu{
position: absolute;
top: -9999px;
left: -9999px;
width: 100px;
border-radius: 3px;
list-style-type: none;
border: 1px solid #8F8F8F;
padding: 2px;
background: #FFFFFF;
}
#menu li{
position: relative;
height: 24px;
padding-left: 24px;
background: #EAEAD7;
vertical-align: top;
}
#menu li a{
display: block;
color: #333333;
background: #FFFFFF;
padding-left: 5px;
text-decoration: none;
}
#menu li.active{
background: #999999;
}
#menu li.active a{
color: #FFFFFF;
background: #8F8F8F;
}
#menu li em{
position: absolute;
top: 0px;
left: 0px;
width: 24px;
height: 24px;
background: url(http://www.codefans.net/jscss/demoimg/201206/ico.png) no-repeat;
}
#menu li em.cur{
background-position: 0px 0px;
}
#menu li em.copy{
background-position: 0px -24px;
}
#menu li em.paste{
background-position: 0px -48px;
}
</style>

<script type="text/javascript">

window.onload = function () {
var oMenu = document.getElementById("menu");
var aLi = oMenu.getElementsByTagName("li");

//加载后隐藏自定义右键菜单
oMenu.style.display = "none";

//菜单鼠标移入/移出样式
for (var i = 0; i < aLi.length; i ++) {
aLi[i].onmouseover = function () {
this.className = "active"
};

aLi[i].onmouseout = function () {
this.className = ""
}
}

//自定义菜单
document.oncontextmenu = function (event) {
var event = event || window.event;
var style = oMenu.style;

style.display = "block";
style.top = event.clientY + "px";
style.left = event.clientX + "px";

return false; // 取消默认行为
};

//页面点击后自定义菜单消失
document.onclick = function (){
oMenu.style.display = "none"
}
};
</script>

</head>
<body>

<center>自定义右键菜单,请在页面点击右键查看效果。</center>
<ul id="menu">
<li><em class="cut"></em><a href="javascript:;">剪切</a></li>
<li><em class="copy"></em><a href="javascript:;">复制</a></li>
<li><em class="paste"></em><a href="javascript:;">粘贴</a></li>
</ul>

</body>
</html>

来源:http://www.bug315.com/article/283.htm

最新文章

  1. 一款强大的Android网络渗透软件dsploit
  2. sql语句的单双引号问题
  3. CUBRID学习笔记 22 插入数据
  4. 【POJ1811】【miller_rabin + pollard rho + 快速乘】Prime Test
  5. 关于oracle卸载没有卸载完全的问题
  6. 深入学习微框架:Spring Boot
  7. UML中类图的符号解释
  8. CSS实现三角形图标的原理《转载》
  9. Nginx 静态资源缓存设置
  10. 堆叠式降噪自动编码器(SDA)
  11. element-ui 修改源码实践 --tranfer
  12. 【转】idea 2018注册码(激活码)永久性的
  13. CSS中一个冒号和两个冒号有什么区别
  14. WebSocket原理与实践(四)--生成数据帧
  15. zabbix入门之使用QQ邮箱接受报警信息
  16. POJ 2528 - Mayor&#39;s posters - [离散化+区间修改线段树]
  17. Adobe漏洞攻击
  18. Rspec: everyday-rspec实操: 第10章测试其他功能,第11章TDD 第12章总结。
  19. arcotg_udc: exports duplicate symbol imx_usb_create_charger (owned by kernel)
  20. thinkphp session设置

热门文章

  1. VisualSVN官网
  2. Android广播BroadcastReceiver 一
  3. Android AIDL Service
  4. ajax跨域jsonp
  5. Sqlserver_left join 、right join、 inner join 用法
  6. vim 学习记录2
  7. easyui 查询
  8. shell如何在指定文件的指定位置后面添加内容
  9. Growing转化的每一步(笔记整理)
  10. Servlet后续的尾(yi)巴--------Filter过滤器