欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于JavaScript實(shí)現(xiàn)智能右鍵菜單

 更新時(shí)間:2016年03月02日 10:28:30   作者:_coding_  
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)智能右鍵菜單的相關(guān)資料,需要的朋友可以參考下

通過本文給大家介紹智能右鍵菜單,需要引入的文件再文末會(huì)給出,先給大家展示下代碼:

具體代碼如下所示:

var cityArray = new Array(); 
cityArray.push("北京"); 
cityArray.push("上海"); 
//設(shè)置表頭的鼠標(biāo)右擊事件 
$('th').mousedown(function(e){ 
var selected = e.target.innerHTML; 
//3表示右鍵 
if(e.which==3){ 
if(selected=="訂票類型"){ 
var opertion ={ 
name : "訂票類型" 
}; 
var data = [[{ 
text:'出票', 
func:function(){ 
alert("出票"); 
} 
}],[{ 
text:'留票', 
func:function(){ 
alert("留票"); 
} 
}],[{ 
text:'改簽', 
func:function(){ 
alert("改簽"); 
} 
}],[{ 
text:'退票', 
func:function(){ 
alert("退票"); 
} 
}],[{ 
text:'全部', 
func:function(){ 
alert("全部"); 
} 
}]]; 
$(this).smartMenu(data,opertion); 
}else if(selected=="出發(fā)城市"){ 
var opertion ={ 
name : "出發(fā)城市" 
}; 
var data = []; 
for(var i=0;i<cityArray.length;i++){ 
//使用閉包 
(function(i){ 
func = function(){ 
alert(cityArray[i]); 
} 
})(i); 
var obj = { 
text:cityArray[i], 
func:func 
}; 
var cArray = new Array(); 
cArray.push(obj); 
data.push(cArray); 
} 
var other = { 
text:"全部", 
func:function(){ 
alert("全部"); 
} 
} 
var otherArray = new Array(); 
otherArray.push(other); 
data.push(otherArray); 
$(this).smartMenu(data,opertion); 
} 
} 
return false;//阻止鏈接跳轉(zhuǎn) 
});

$('th') 指定加右鍵的標(biāo)簽,根據(jù)實(shí)際來確定 我這里是加在表格的表頭上,所以是th標(biāo)簽
e.which = 3 表示是右鍵

這里列出了兩種情況

一種是菜單上的內(nèi)容確定 用前面一種opertion定義該右鍵菜單的名稱,要唯一

另一種是不確定 可以通過從服務(wù)端獲取數(shù)據(jù),存儲(chǔ)在數(shù)組中,我這里寫死了,然后用第二種方式實(shí)現(xiàn) 其中需要用到閉包

需要引入的文件:http://download.csdn.net/detail/u012116457/9449905

以上內(nèi)容是小編給大家分享的基于JavaScript實(shí)現(xiàn)智能右鍵菜單的相關(guān)知識(shí),希望對(duì)大家有所幫助!

相關(guān)文章

最新評(píng)論