请在这里查看示例 ☞ contextmenu示例
兼容性:ie8+
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″/>
<link rel="stylesheet" href="http://v3.faqrobot.org/hvb/com/css/reset.css?dev=1">
<script type="text/javascript" src="http://v3.faqrobot.org/hvb/com/js/jquery-1.11.3.min.js?dev=1"></script>
<script type="text/javascript" src="http://v3.faqrobot.org/hvb/com/js/base.js?dev=1"></script>
<title>svg</title>
<style>
body, html {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script>
;$(function() {
$(document).on('contextmenu', function(e) {
if($('.CM_contextmenu')[0]) {
}else {
var $style = $('<style>.CM_contextmenu{width:200px;padding:2px 0;position:fixed;z-index:99999;background:#fff;border:1px solid #ddd;}.CM_item{padding:5px 10px;position:relative;cursor:default;font-size:12px;}.CM_item:hover{color:#fff;background:#4281F4;}</style>').appendTo('head');
var $div = $('<div class="CM_contextmenu"><div class="CM_reload CM_item">重新加载</div><div class="CM_check CM_item">检查</div></div>').appendTo('body');
}
$('.CM_contextmenu').show().css({
left: e.clientX,
top: e.clientY,
});
return false;
});
//隐藏
$('body').on('click', function(e) {
if(!$(e.target).is('.CM_contextmenu') && !$(e.target).is('.CM_item')) {
$('.CM_contextmenu').hide();
}
});
//重新加载
$('body').on('click', '.CM_reload', function() {
$('.CM_contextmenu').hide();
document.location.reload();
});
});
</script>
</body>
</html>