2

我div有類名「.modalPopup」裏面的div我有多個表和裏面的表我有div和裏面的多個控件如文本框(輸入)和下拉列表(選擇)。jQuery的選擇器使用不是

我想要的是,當用戶點擊任何位於具有「modalPopup」除了下拉列表(選擇)的主div上的點擊事件。 我嘗試使用我的選項,但我不能得到具體的點擊事件。 like

$('.modalPopup :not(modalPopup select)').click(function(){ 
    document.write("working for click except select "); 
    }); 

任何人都請給我提供解決方案。

回答

0

最簡單方法是單擊事件只是綁定與類的modalPopup股利,然後檢查用戶實際點擊使用e.target

$('.modalPopup').click(function(e){ 
    if (!$(e.target).is('select')) { 
     document.write("working for click except select "); 
    } 
}); 

e.target是被點擊的DOM元素。 $(e.target).is('select')獲取該dom元素並從中創建一個jQuery對象並檢查它是否爲select。

JSFiddle Example

+0

你可以請張開它「if(!$(e.target).is('select'))」。我非常感謝你... – 2012-01-04 12:56:43

+0

@ user1129558當然 - 請參閱我的編輯 – 2012-01-04 13:34:43

+0

感謝@Richard D的解釋。 – 2012-01-05 05:07:58

0

您在not()條件中缺少.modalPopup之前的點。

$('.modalPopup :not(.modalPopup select)').click(function(){ document.write("working for click except select "); }); 
+0

我想念點,而這裏打字..我找到幫助solution.thanks。 – 2012-01-04 12:57:46