【发布时间】:2011-09-14 13:56:07
【问题描述】:
我使用 jquery 的插件 - ContextMenu。 - http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/
我在页面中心有一个 div。我在点中有背景图像。我需要它只在背景图像上使用 jquery 右键单击。如果单击背景图像,那么我想显示 ContextMenu。如果单击 id 为 divPage 的 div,则不会发生任何事情。
感谢您的建议或可能的其他解决方案。
HTML
<body>
<form id="formBackground" method="post">
<ul id="myMenu" class="contextMenu">
<li class="insert"><a href="#insert">Add New</a></li>
<li class="edit"><a href="#edit">Edit</a></li>
<li class="delete"><a href="#delete">Delete</a></li>
</ul>
<div id="divPage">
Text.
</div>
</form>
CSS
body, html {
height: 100%;
}
body{
padding: 0px;
margin: 0px;
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12px;
color: white;
background-image: url('../images/backgrounds/bg.jpg');
background-repeat:no-repeat;
background-position:top;
}
div#divPage{
width: 800px;
height: 300px;
margin: auto;
}
JS
$('body').bind('mousedown', function (evt) {
switch (evt.which) {
case 3:
if(evt.target == $('body')[0]) {
//Show context menu
}
break;
}
});
【问题讨论】:
标签: jquery contextmenu background-image right-click