2011-01-09 36 views
4

我正在研究下面插件的代碼,並想知道它在何時何地與「右鍵單擊」事件相關聯。它所做的就是jquery上下文菜單插件 - 右鍵單擊​​事件類型在哪裏?

插件參考鏈接:http://www.javascripttoolbox.com/lib/contextmenu/

$(this).bind('contextmenu',function(e){cmenu.show(this,e);return false;});

和 「文本菜單」 是一個自定義的jQuery事件類型。

能有人請解釋這一切是如何工作的

我做了檢查有單擊事件,但這些都是聯繫在一起的菜單項而不是元素到菜單綁。

謝謝

答案:「contextmenu」不是自定義事件類型。它實際上是另外一個名字(映射等)爲「右鍵單擊」

回答

2

contextmenu自定義jQuery的事件(看看它here的MDC文章)。所有插件正在爲此事件綁定事件處理程序並顯示/隱藏菜單。

+0

哦!我覺得我好笨。謝謝安德魯再次來救我:) – Nilesh 2011-01-09 23:27:56

1

文本菜單是觸發JavaScript事件在用戶右鍵點擊一個元素,如果你想用這個事件來實現自己的功能,你可以做這樣的事情:

$("element").bind("contextmenu",function(){ 
    //your code here 
}); 

什麼發生在插件代碼如下:

$(this).bind('contextmenu',function(e){ //capture right click on "this" which 
             //is the element being clicked 
    cmenu.show(this,e); //call function cmenu.show to show the menu and pass two arguments 
         //the element clicked "this: and the event data "e" 

    return false; //this cancels the default context menu 
}); 
相關問題