求js 自定义右键菜单代码,只要在网页上右键弹出菜单就行
发布网友
发布时间:2022-04-26 12:43
我来回答
共1个回答
热心网友
时间:2022-04-07 07:26
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#ul1 {width:100px; background:#CCC; border:1px solid black; position:absolute; display:none;margin:0; padding:0;}
#ul1 li{list-style:none}
</style>
<script>
document.oncontextmenu=function(ev){
var oEvent=ev||event;
var oUl=document.getElementById('ul1');
oUl.style.display='block';
oUl.style.left=oEvent.clientX+'px';//如果超出可视区就加scroll
oUl.style.top=oEvent.clientY+'px';
return false;
}
document.onclick=function ()
{
var oUl=document.getElementById('ul1');
oUl.style.display='none';
};
</script>
</head>
<body>
<ul id="ul1">
<li>自己添加</li>
<li>2</li>
</ul>
</body>
</html>