点击这里体验效果

如果要屏蔽页面原来的右键菜单,请设置disable_native_context_menu:true

以下是源代码:

 <!DOCTYPE html>
<html>
<head>
<title>jQuery右键菜单,上下文菜单-柯乐义</title>
<script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery-1.8.2.min.js"
charset="utf-8"></script>
<style type="text/css" media="screen">
html, body
{
height: 100%;
} body
{
font-family: 'lucida grande' , tahoma, verdana;
font-size: 15px;
color: #555;
width: 700px;
margin: 0 auto;
padding: 30px 0;
} h1, h2
{
color: #222;
} ul
{
list-style-type: none;
list-style-position: inside;
margin: 0;
padding: 0;
} /* all context menus have this class */
.context-menu
{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: #f2f2f2;
border: 1px solid #999;
list-style-type: none;
margin: 0;
padding: 0;
}
.context-menu a
{
display: block;
padding: 3px;
text-decoration: none;
color: #333;
}
.context-menu a:hover
{
background-color: #666;
color: white;
} /* second context menu */
#context-menu-2
{
border: 1px solid #333;
background-color: orange;
margin: 0;
padding: 0;
} .target1, .target2 li, .target3 li
{
background-color: #ddd;
color: #333;
border: 1px solid #c6c6c6;
padding: 5px;
} .target1
{
width: 130px;
} .target2 li, .target3 li
{
margin-top: 5px;
} .target1 li.green, .target2 li.green, .target3 li.green
{
background-color: green;
color: #fff;
} .big-font
{
font-size: 25px;
}
</style>
</head>
<body>
<h1>
jQuery右键菜单示例·柯乐义</h1>
<h2>
例 1</h2>
<p>
单个div的上下文菜单。 Note that the native context menu is disabled by passing {disable_native_context_menu:
true} as the options hash and last argument of the plugin. The native context menu
is enabled by default.
</p>
<div class="target1">
右击我</div>
<h2>
例 2 - 使用鼠标左键点击</h2>
<p>
You can use the same syntax, but use any other selector to target multiple elements
with the same context menu. Notice the leftClick: true which indicates that it should
trigger on left click instead of right click.
</p>
<ul class="target2">
<li>请左击我,右击没效果。</li>
<li>请左击我,右击没效果。</li>
<li>请左击我,右击没效果。</li>
</ul>
<a href ="http://keleyi.com/a/bjac/qjaheda1.htm" target="_blank">原文</a><br />
<h2>
例 3 - 突出当前点击项</h2>
<p>
You can use the showMenu and hideMenu options to highlight the current context menu
target.
</p>
<ul class="target3">
<li>右击我</li>
<li>右击我</li>
<li>右击我</li>
</ul>
<div>
本插件的不足支出就是不支持jquery1.9以上版本。</div>
<script src="http://keleyi.com/keleyi/phtml/jqplug/8/jquery.contextMenu.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
//例1
$('.target1').contextMenu('context-menu-1', {
'右键菜单项1': {
click: function (element) { // element is the jquery obj clicked on when context menu launched
alert('点击了右键菜单项');
},
klass: "menu-item-1" // a custom css class for this menu item (usable for styling)
},
'右键菜单项2': {
click: function (element) { alert('点击了第二项'); },
klass: "second-menu-item"
}, '返回首页': { click: function (element) { location.href = "http://keleyi.com"; } }
});
//例2
$('.target2 li').contextMenu('context-menu-2', {
'彩上绿色!': {
click: function (element) { // element is the jquery obj clicked on when context menu launched
element.addClass('green');
},
klass: "menu-item-1" // a custom css class for this menu item (usable for styling)
},
'变大!': {
click: function (element) { element.addClass('big-font') },
klass: "second-menu-item"
}, '打开原文': { click: function (element) { window.open("http://keleyi.com/a/bjac/qjaheda1.htm"); } }
}, { disable_native_context_menu: true, leftClick: true }
);
//例3
$('.target3 li').contextMenu('context-menu-2', {
'变大!': {
click: function (element) { element.addClass('big-font') },
klass: "menu-item-1" // a custom css class for this menu item (usable for styling)
}
}, {
disable_native_context_menu: true,
showMenu: function (element) { element.addClass('green'); },
hideMenu: function (element) { element.removeClass('green'); }
});
});
</script>
</body>
</html>

转载自:http://keleyi.com/a/bjac/qjaheda1.htm

http://www.cnblogs.com/jihua/p/webfront.html

jquery右键菜单的更多相关文章

  1. 几款jQuery右键菜单插件介绍

    在网页中使用自定义右键菜单,实现上皆为使用javascript禁用浏览器默认的右键菜单,然后在网页中响应鼠标右键事件,弹出自定义的菜单. 类似右键菜单的组件网上很多.一般而言,改变浏览器的默认菜单应当 ...

  2. jQuery右键菜单contextMenu使用实例

    在最近项目中需要频繁的右键菜单操作.我采用了contextMenu这款jQuery插件. 参考网址:http://www.jb51.net/article/58709.htm 官网demo http: ...

  3. Jquery 右键菜单(ContextMenu)插件使用记录

    目前做的项目需要在页面里面用右键菜单,在网上找到两种jquery的右键菜单插件,但是都有各种问题.所以就自己动手把两种插件结合了下. 修改后的右键菜单插架可以根据绑定的触发页面元素不同,复用同一个菜单 ...

  4. js jQuery 右键菜单 清屏

    主要用到了oncontextmenu事件,在oncontextmenu事件中使用return false 屏蔽掉原生右键菜单,再使用event获取鼠标的坐标位置,设置自定义菜单的位置. http:// ...

  5. jQuery右键菜单contextMenu实例

    URL: http://www.cnblogs.com/whitewolf/archive/2011/09/28/2194795.html http://www.blogjava.net/superc ...

  6. js(jquery)右键菜单插件的实现

    今天开发一个项目的时候需要一个模拟鼠标右键菜单的功能.也就是在网页点击鼠标右键的时候不是弹出系统的菜单而是我们制定的内容.这样可以拓展右键的功能.实现过程不多说了,写出来的代码和效果如下: js部分: ...

  7. jQuery右键菜单ContextMenu使用笔记

    插件下载地址:http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.packed.js 和http://ww ...

  8. 几款jQuery右键菜单插件

    1.jQuery Very Simple ContextMenu Plugin 2.ContextJS Project Page:http://lab.jakiestfu.com/contextjs/ ...

  9. JQuery之ContextMenu(右键菜单)

    插件下载地址:http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.js压缩版:http://www.tre ...

随机推荐

  1. C语言-指针

    C指针基础知识 C语言中,指针无疑是最令人头疼的.今天无事就来学学C语言的指针,在此留下点笔记,仅供个人参考. 首先要搞懂的是,指针是什么? 指针:是用来存放内存地址的变量. 不管是什么类型的指针,存 ...

  2. 用Mindjet MindManager 15 打开文件后停止响应的解决方法

    这个是因为文件里面有很多规格不统一的注释(那个像小本子的图标[里面就是注释部分]),默认编码是utf-8的,如果不一样的话就会出现这个问题.网上大多数都是让咱们删掉注释再打开 弱弱的问一下,如果我都把 ...

  3. 【原创】开源Math.NET基础数学类库使用(17)C#计算矩阵条件数

                   本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新  开源Math.NET基础数学类库使用总目录:[目录]开源Math.NET基础数学类库使用总目录 上个月 ...

  4. Util应用程序框架公共操作类(二):数据类型转换公共操作类(源码篇)

    上一篇介绍了数据类型转换的一些情况,可以看出,如果不进行封装,有可能导致比较混乱的代码.本文通过TDD方式把数据类型转换公共操作类开发出来,并提供源码下载. 我们在 应用程序框架实战十一:创建VS解决 ...

  5. 关于SVN链接服务器Unable to connect to a repository at URL*报错问题

    在BAE上托管了写代码,想用SVN做版本控制,可是死活连不上,但用Dreamweave可以连上,整了半天是dan疼的缓存问题,清一下缓存就OK了. TortoiseSVN->Setting-&g ...

  6. CentOS初始化Mysql5.7密码

    /etc/init.d/mysql stopmysqld_safe --user=mysql --skip-grant-tables --skip-networking &mysql -u r ...

  7. 1Z0-053 争议题目解析698

    1Z0-053 争议题目解析698 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 698.In your production database, you: -Are using ...

  8. Solr学习总结(六)SolrNet的高级用法(复杂查询,分页,高亮,Facet查询)

    上一篇,讲到了SolrNet的基本用法及CURD,这个算是SolrNet 的入门知识介绍吧,昨天写完之后,有朋友评论说,这些感觉都被写烂了.没错,这些基本的用法,在网上百度,资料肯定一大堆,有一些写的 ...

  9. jQuery 插件为什么要return this.each()

    jQuery.fn.test2= function(){ this.css("background","#ff0");//这里面的this为jquery对象,而 ...

  10. CSS3 media queries + jQuery实现响应式导航

    目的: 实现一个响应式导航,当屏幕宽度大于700px时,效果如下: 当屏幕宽度小于700px时,导航变成一个小按钮,点击之后有一个菜单慢慢拉下来: 思路: 1.为了之后在菜单上绑定事件,并且不向DOM ...