2009-03-19 4 views

답변

6

그것은 jQuery를에서 기본적으로 지원되지 않습니다,하지만 당신은 hasEvent plugin을 사용하여 자신 만의 선택을 작성할 수 있습니다

jQuery.expr[":"].click = "jQuery(a).hasEvent('click');"; 

$("a:click").doStuff(); 

편집 : 또한보다 완전하고 밖으로 작동 Event Bound Selector plugin있다

상자,하지만 또한 더 큽니다. 위치에 대한

+0

좋아요. 나는 그것이 어떻게 작동하는지 궁금해. – Vasil

0

아니요. 모든 요소를 ​​반복하고 이벤트 바인딩이 있는지 확인할 수 있습니다. 그러나 어떤 종류의 요소가 해당 이벤트 바인딩을 가지므로 검색 범위를 좁힐 수 없다는 단서가없는 한 그렇게 효율적이지 않습니다.

+0

그렇게 끔찍하게 ineffecient되지 않을 수도 있기 때문에 jquery가 모든 쿼리에 대해 모든 것을 반복한다고 의심합니다. – cobbal

0

검색 :

button: function(elem){ 
     return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; 
    }, 
    input: function(elem){ 
     return /input|select|textarea|button/i.test(elem.nodeName); 
    }, 
    //init custom 
    ev: function(elem,i,match){ 
     var what = $(elem).hasEvent(match[3]); 
     var type = (typeof what); 
     return what !== null && type !== undefined; 
    } 
    //End custom 
}, 
setFilters: { 
    first: function(elem, i){ 
     return i === 0; 
    }, 
    last: function(elem, i, match, array){ 
     return i === array.length - 1; 
    }, 
    even: function(elem, i){ 
     return i % 2 === 0; 
    }, 

.....

같은 사용과 같은 has()

예 :

$('form:ev(submit)'); 
$('input:ev(click)'); 
$('a:ev(click)');