<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function () {
$("#d1").bind('contextmenu ', function (e) {
e.preventDefault();
var temptop = e.clientY - 50;
var templeft = e.clientX - 50;
//在点击点四周创建长度为50px的正方形div,离开,就移除 这个div 和 tt
var temparea = "<div id='temp' style='position:absolute;height:100px;width:100px;top:" + temptop + "px;left:" + templeft + "px;text-align:center;line-height:100px;'>测试</div>";
//var item = $("#tip");
//$("#tip").append($("<p>666</p>"));
//$("#tip").css({ 'top': e.clientX + 'px', 'left': e.clientY + 'px' });
//$("#tip").show();
$("#temp").css({ 'top': e.clientY + 10 + 'px', 'left': e.clientX + 10 + 'px' }).show();
$("body").append(temparea).show();
$("#temp").bind('click', function () {
console.log("temp click");
$("#temp").remove();
});
$("#temp").mouseleave(function () {
$("#temp").remove();
});
});
});
</script>
</head>
<body>
<div style="height:300px;width:300px;background-color:pink;" id="d1">
</div>
</body>
</html>
右击时,会在点击的地方出现一个图标
当鼠标离开周围时,图标自动消失
挡鼠板点击图标时,触发事件