jquery怎样弹出右键菜单,请教!

jquery怎样弹出右键菜单,请教!给个详细的例子,不要复杂的,谢谢... jquery怎样弹出右键菜单,请教!给个详细的例子,不要复杂的,谢谢 展开
 我来答
zourong2791165
2011-05-04 · TA获得超过614个赞
知道小有建树答主
回答量:388
采纳率:0%
帮助的人:616万
展开全部
先来源码,把这一段存成文件,在要使用的页面里面导入于jquery基本库后。
------------
jQuery.fn.extend({
jsRightMenu: function(options) {
options = $.extend({
menuList: []
}, options);
return this.each(function() {
if ($("#div_RightMenu", $(this)).size() == 0) {
var menuCount = options.menuList.length;
if (menuCount > 0) {
var divMenuList = "<div id=\"div_RightMenu\" class=\"div_RightMenu\">";
for (var i = 0; i < menuCount; i++) {
divMenuList += "<div class=\"divMenuItem\" onclick=\"" + options.menuList[i].clickEvent + "\" onmouseover=\"" + options.menuList[i].mouseoverEvent + "\" onmouseout=\"" + options.menuList[i].mouseoutEvent + "\">" + options.menuList[i].menuName + "</div>";
}
divMenuList += "</div>";
$(this).append(divMenuList);
var objM = $(".divMenuItem");
$("#div_RightMenu").hide();
objM.bind("mouseover", function() {
this.style.backgroundColor = "#316ac5";
this.style.paddingLeft = "30px";
});
objM.bind("mouseout", function() {
this.style.backgroundColor = '#EAEAEA';
});
}
}
this.oncontextmenu = function() {
var objMenu = $("#div_RightMenu");
if (objMenu.size() > 0) {
objMenu.hide();
var event = arguments[0] || window.event;
var clientX = event.clientX;
var clientY = event.clientY;
var redge = document.body.clientWidth - clientX;
var bedge = document.body.clientHeight - clientY;
var menu = objMenu.get(0);
var menuLeft = 0;
var menuTop = 0;
if (redge < menu.offsetWidth)
menuLeft = document.body.scrollLeft + clientX - menu.offsetWidth;
else
menuLeft = document.body.scrollLeft + clientX;
if (bedge < menu.offsetHeight)
menuTop = document.body.scrollTop + clientY - menu.offsetHeight;
else
menuTop = document.body.scrollTop + clientY;
objMenu.css({ top: menuTop + "px", left: menuLeft + "px" });
objMenu.show();
return false;
}
}
document.onclick = function() {
var objMenu = $("#div_RightMenu");
if (objMenu.size() > 0) objMenu.hide();
}
});
}
});

-------------------------------------------------------
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="jquery.menu.js"></script>
<div id="divTest">右键菜单显示区域</div>
<script type="text/javascript">
$(function() {
$("#divTest" ).jsRightMenu({
menuList: [{ menuName: "右键菜单1", clickEvent: "divClick('1')"},
{ menuName: "右键菜单2", clickEvent: "divClick('2')"},
{ menuName: "右键菜单3", clickEvent: "divClick('3')"},
{ menuName: "右键菜单4", clickEvent: "divClick('4')"},
{ menuName: "右键菜单5", clickEvent: "divClick('5')"}
]
});
});
function divClick(id){
alert("你点了--右键菜单"+id);
}
</script>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式