javascript鼠標(biāo)右鍵菜單自定義效果
本文實(shí)例講解了javascript鼠標(biāo)右鍵菜單的實(shí)現(xiàn)方法,分享給大家供大家參考,具體內(nèi)容如下
效果圖:

具體代碼:
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
#menu{
border:solid 1px gray;
width:100px;
display:none;
position:absolute;
background-color:ghostwhite;
margin: 0;
padding: 0;
list-style-type: none;
}
#menu>li{
border-bottom: dashed 1px gray;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oUl=document.getElementById('menu');
document.oncontextmenu=function(ev){
var oEvent=ev||event;
//一定要加px,要不然chrom不認(rèn)
oUl.style.top=oEvent.clientY+'px';
oUl.style.left=oEvent.clientX+'px';
oUl.style.display='block';
return false;
}
document.onclick=function(){
oUl.style.display='none';
}
};
</script>
</head>
<body>
<ul id="menu">
<li><a href="http://www.dhdzp.com/" target="_blank">腳本之家</a></li>
<li><a href="http://www.dhdzp.com/" target="_blank">腳本之家</a></li>
<li><a href="http://www.dhdzp.com/" target="_blank">腳本之家</a></li>
<li><a href="http://www.dhdzp.com/" target="_blank">腳本之家</a></li>
</ul>
</body>
</html>
希望本文所述對(duì)大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
使用JS中的Replace()方法遇到的問(wèn)題小結(jié)
這篇文章主要介紹了使用JS中的Replace()方法遇到的問(wèn)題小結(jié),需要的朋友可以參考下2017-10-10
將HTML格式的String轉(zhuǎn)化為HTMLElement的實(shí)現(xiàn)方法
本節(jié)主要介紹了將HTML格式的String轉(zhuǎn)化為HTMLElement的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-08-08
js倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了js倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)方法,方便一些提示重要日期的來(lái)臨,感興趣的小伙伴們可以參考一下2015-12-12
使用JavaScript優(yōu)雅實(shí)現(xiàn)文本展開(kāi)收起功能
這篇文章主要為大家詳細(xì)介紹了如何使用JavaScript優(yōu)雅實(shí)現(xiàn)文本展開(kāi)收起功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04
javascript獲取四位數(shù)字或者字母的隨機(jī)數(shù)
這篇文章主要介紹了javascript獲取四位數(shù)字或者字母的隨機(jī)數(shù),需要的朋友可以參考下2015-01-01
JavaScript實(shí)現(xiàn)類(lèi)似淘寶的購(gòu)物車(chē)效果
這篇文章主要介紹了JavaScript實(shí)現(xiàn)購(gòu)物車(chē)特效的相關(guān)資料,文中通過(guò)示例代碼詳細(xì)介紹了,利用Javascript如何實(shí)現(xiàn)類(lèi)似淘寶購(gòu)物車(chē)中商品的單選、全選、刪除、修改等功能,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-03-03

