2

div에 클래스 이름이 ".modalPopup"인 div가 있습니다. 여러 테이블과 내부 테이블에 div가 있고 텍스트 상자 (입력) 및 드롭 다운리스트 (선택)와 같은 여러 컨트롤이 있습니다.Jquery Selector를 사용하지 않는 경우

나는 dropuplist (select)를 제외하고 "modalPopup"이있는 main div의 아무 곳이나 클릭 할 때 click 이벤트를 발생시키고 싶습니다. 내 옵션을 사용하려고 시도하지만 특정 클릭 이벤트를 가져올 수 없습니다.

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

처럼 어떤 사람은 나에게 솔루션을 제공하십시오.

답변

0

가장 쉬운 방법은 modalPopup의 클래스 사업부의 클릭 이벤트를 바인딩하고 e.target을 사용하여 사용자가 실제로 클릭 것을 확인하는 것입니다 . $(e.target).is('select')은 dom 요소를 가져 와서 jQuery 객체를 만들고 선택인지 확인합니다. .. 내가 도움의 solution.thanks을 찾아 여기에 입력하는 동안

JSFiddle Example

+0

if (! $ (e.target) .is ('select'))) "를 expalain 주시겠습니까? 나는 그 점에 대해 당신에게 매우 감사하고 있습니다. ... –

+0

@ user1129558 확실한 - 내 편집보기 –

+0

설명을위한 @Richard D. –

0

not() 조건에서 .modalPopup 전에 점이 누락되었습니다.

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

e.target가 클릭 된 DOM 요소입니다 :

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

가 나는 점을 놓친다. –

관련 문제