2011-09-28 31 views
0

是否有人使用jQuery Easy Confirmation插件遇到此問題 - 在第一次單擊後,確認框綁定的按鈕會丟失其原始的單擊事件?我不得不改變插件代碼來使它工作。這裏的區別在於.bind和.click之間。誰能解釋爲什麼? PLS。讓我知道如果我的問題不明確。謝謝!.bind()語句在jQuery Easy Confirmation插件中不起作用

原來的插件代碼:

 // Re-bind old events 
      var rebindHandlers = function() { 

       if (target._handlers != undefined) { 
        jQuery.each(target._handlers, function() { 
         //this is the difference 
         $target.bind(type, this); 
        }); 
       } 
      } 

改變(工作)代碼:

// Re-bind old events 
      var rebindHandlers = function() { 

       if (target._handlers != undefined) { 
        jQuery.each(target._handlers, function() { 
         //this is the difference 
         if(type == 'click') 
          $target.click(this); 
         else { 
          $target.bind(type, this); 
         } 
        }); 
       } 
      } 

回答

0

嘗試使用一些警報,看看發生了什麼......

// Re-bind old events 
var rebindHandlers = function() { 
      if (target._handlers != undefined) { 
       jQuery.each(target._handlers, function() { 
        if(type == 'click') 
         alert('$target.click(' + this + ');'); 
         //$target.click(this); 
        else { 
         alert('$target.bind(' + type + ', ' + this + ');'); 
         //$target.bind(type, this); 
        } 
       }); 
      } 
     }