<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
#ul1 li {
width: 400px;
background: #CCC;
border: 1px solid black;
margin: 10px;
float: left;
line-height: 30px;
text-indent: 1em;
}
#menu {
width: 150px;
border: 1px solid black;
border: 1px solid black;
position: absolute;
left: 0;
top: 0;
display: none;
background: white;
}
#menu li {
padding: 3px;
}
#menu li:hover {
background: #CCC;
}
</style>
<script>
window.onload = function() {
var aLi = document.getElementById('ul1').children;
var oMenu = document.getElementById('menu');
var aMenuLi = oMenu.children;
for(var i = 0; i < aLi.length; i++) {
aLi[i].oncontextmenu = function(ev) {
var oEvent = ev || event;
oMenu.style.display = 'block';
oMenu.style.left = oEvent.clientX + 'px';
oMenu.style.top = oEvent.clientY + 'px';
var _this = this;
aMenuLi[0].onclick = function() {
_this.parentNode.removeChild(_this);
};
return false;
};
}
document.onclick = function() {
oMenu.style.display = 'none';
};
};
</script>
</head>
<body>
<ul id="menu">
<li>删除</li>
<li>111</li>
<li>22</li>
<li>33</li>
<li>4444</li>
</ul>
<ul id="ul1">
<li>1111</li>
<li>2222</li>
<li>33333</li>
<li>44444</li>
<li>55555</li>
<li>6666</li>
</ul>
</body>