var ul = document.createElement("ul");
ul.style.display = "none";
document.body.appendChild(ul);
var arr = ["vue", "react", "angular"];
for (var i = 0; i < arr.length; i++) {
var li = document.createElement("li");
7;
li.innerText = arr[i];
ul.appendChild(li);
setStyle(li, {
padding: "10px 0",
margin: 0,
});
}
window.oncontextmenu = function () {
var e = window.event;
var x = e.pageX;
var y = e.pageY;
setStyle(ul, {
width: "100px",
display: "block",
listStyle: "none",
padding: 0,
margin: 0,
border: "1px solid #ccc",
position: "absolute",
left: x + 20 + "px",
top: y + 20 + "px",
});
return false;
};
document.onclick = function () {
console.log(ul)
ul.style.display = "none";
};
ul.onmouseover = function () {
for (i = 0; i < ul.children.length; i++) {
ul.children[i].style.backgroundColor = "";
}
var e = window.event;
var target = e.target || e.srcElement;
if (target.tagName === "LI") {
target.style.backgroundColor = "#ccc";
}
};
ul.onclick = function () {
var e = window.event;
var target = e.target || e.srcElement;
if (target.tagName === "LI") {
document.write("你选择了" + target.innerText);
}
};
```