簡體   English   中英

我應該如何在javascript中的已處理鍵盤事件中引用調用對象

[英]how should i refer to the calling object within a handled keyboard event in javascript

嗨,我正在編寫一個處理鍵盤事件的javascript小部件。 當我顯示div並想在有人按esc時將其隱藏時,就會出現有問題的問題。

實現以下目標的最佳方法是什么(我在此項目中使用jquery)

var escToExit = function(e){
   // code to check for esc
  // i then want to call the instance of widget that is linked to this function
}
var widget = {
  show : function(){
    $(document).keyup(escToExit);
  },
  hide : function(){
    //hide code here
  }
}

謝謝

編輯

按值:

var escToExit = function(e){
  e.data.wpass; // here is your ref
  // rest of func
}

var widget = {
  show : function() {
    $(document).bind('keyup', {wpass : widget}, escToExit);
  // rest of obj
}

看到

http://api.jquery.com/bind/

http://api.jquery.com/trigger/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM