Intelligent right click menu based on JavaScript

  • 2021-01-19 22:02:25
  • OfStack

Through this article to introduce the intelligent right click menu, the need to introduce the file will be given at the end of the article, first to show you the code:

The specific code is as follows:


var cityArray = new Array(); 
cityArray.push(" Beijing "); 
cityArray.push(" Shanghai "); 
// Sets the right-click event for the header  
$('th').mousedown(function(e){ 
var selected = e.target.innerHTML; 
//3 Said right  
if(e.which==3){ 
if(selected==" Booking type "){ 
var opertion ={ 
name : " Booking type " 
}; 
var data = [[{ 
text:' The drawer ', 
func:function(){ 
alert(" The drawer "); 
} 
}],[{ 
text:' Leave a ticket ', 
func:function(){ 
alert(" Leave a ticket "); 
} 
}],[{ 
text:' endorse ', 
func:function(){ 
alert(" endorse "); 
} 
}],[{ 
text:' refund ', 
func:function(){ 
alert(" refund "); 
} 
}],[{ 
text:' all ', 
func:function(){ 
alert(" all "); 
} 
}]]; 
$(this).smartMenu(data,opertion); 
}else if(selected==" Departure city "){ 
var opertion ={ 
name : " Departure city " 
}; 
var data = []; 
for(var i=0;i<cityArray.length;i++){ 
// Using closures  
(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:" all ", 
func:function(){ 
alert(" all "); 
} 
} 
var otherArray = new Array(); 
otherArray.push(other); 
data.push(otherArray); 
$(this).smartMenu(data,opertion); 
} 
} 
return false;// Prevents link jumps  
});

$('th'); $('th'); $('th')
e.which = 3 means right click

Two scenarios are listed here

1 is the content of the menu. Make sure to define the name of the right-click menu using the previous opertion option. Only 1 is required

The other one is you can do it by getting the data from the server, storing it in an array, I'll write it down here, and then you can do it in the second way where you need a closure

Need to introduce file: http: / / download csdn. net/detail/u012116457/9449905

The above content is the site to share with you based on JavaScript to achieve intelligent right-click menu knowledge, I hope to help you!


Related articles: