js 右键菜单

<!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 id="Head1" runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var mouseX;
var mouseY;
$(document).bind("contextmenu", function (e) { //去掉默认右键功能
return false;
});
$(document).mousedown(function (e) {
mouseX = e.clientX;
mouseY = e.clientY;
if (3 == e.which) { //右键单击
$("#area").css('margin-left', mouseX);
$("#area").css('margin-top', mouseY);
$("#area").show();
} else if (1 == e.which && !($('#area').find(e.target).length != 0 || $('#area')[0] == $(e.target)[0])) { //左键单击
$("#area").hide();
}
return
})

}) 
</script>
</head>
<body>
<form id="form1" runat="server">
<div> 
<div id="area" style="150px; height:200px; background-color:red; display:none;" >
<input type="button" value="我是按钮" onmousedown="alert('11');" />
</div>
</div>
</form>
</body>
</html>

  

原文地址:https://www.cnblogs.com/wdw31210/p/2540262.html