2011-03-28 79 views
0

我有2點擊處理程序爲相同的元素。jQuery錯誤點擊元素與2點擊處理程序

說#1

$(':input, a').bind('click', function(e) { 
    if(e.ctrlKey) { 
    // do something with all links and inputs 
    } 
}); 

和#2:

$('a#some-special-link').click(function() { 
// do something special also with current link only 
}); 

當我點擊一次鏈接的 「A#一些特鏈接」我總是得到一個錯誤裏面的jQuery核心行: return typeof jQuery!==「undefined」& &!jQuery.event.triggered?

if (!eventHandle) { 
    elemData.handle = eventHandle = function() { 
     // Handle the second event of a trigger and when 
     // an event is called after a page has unloaded 
     return typeof jQuery !== "undefined" && !jQuery.event.triggered ? 
      jQuery.event.handle.apply(eventHandle.elem, arguments) : 
      undefined; 
    }; 
} 

錯誤說: 類型錯誤:2200來源:HTTP:行類型錯誤//localhost/js/jquery-1.5.1.js

該錯誤只發生在第一次點擊#some-special-link鏈接。每次下一次雙擊處理程序都可以正常工作。

我不確定是什麼原因。我需要的是執行#1和#2點擊處理程序。

請幫我找什麼在那裏發生的...

更新:我得到同樣的錯誤(當我改變徘徊的情況下,和懸停鼠標的任何鏈接或輸入):

$(':input, a').bind('hover', function(e) ... 

回答

0

您可以縮短第二個點擊處理程序與onclick =「someFunction();」的綁定嗎?既然它是你正在尋找綁定的ID,那麼應該只有一個與第二個選擇器一起返回的元素?所以你的代碼看起來是這樣的:

$(':input, a').bind('click', function(e) { 
    if(e.ctrlKey) { 
    // do something with all links and inputs 
    } 
}); 

...

<a id="some-special-link" onclick="someFunction();"></a> 

HTH

+0

我只能在#1單擊處理程序編輯,我無法改變既不#2點擊處理,也不「特殊鏈接」標籤定義 – Zelid 2011-03-28 21:05:31