2011-02-24 6 views
3

이러한 상황에서 발생하는 입력에 이벤트를 정의 할 수 있습니까?jquery는 자체 이벤트를 정의합니까?

 
a) is called on blur of input IF the remaining conditions are true 
b) if the autocomplete list is visible halt the event until it is closed 
c) if the autocomplete list closes without an item being selected then the event is fired 
d) if the autocomplete list closes with an item being selected the event is not fired 
e) if the reason the blur was caused was because an item in the autocomplete was clicked the event is not fired 

여러분도 알다시피 이벤트에는 꽤 많은 것이 있습니다. 실제로 아무것도 선택하지 않고도 자동 완성 목록에 앉아있을 수 있기 때문에 blur 이벤트에서 일반적인 setTimeout을 사용할 수 없습니다.

어쩌면 내가 변수가 자동 완성으로 설정되어 열려 있다고 알 수 있습니다.
타이머가 만료되고 자동 완성이 열려 있으면 타이머를 재설정 할 수 있습니다.
다음에 변수를 설정 해제 할 수 있습니다.
또는 항목 선택시 타이머를 설정 해제 할 수 있습니까?

당신은 어떻게 생각하십니까?

답변

5

그것은 Trigger 기능을 사용하여 자신의 이벤트를 트리거 할 수 있습니다. 즉, 코드에서 별도의 지점에서 이벤트를 호출 할 수 있으므로 복잡한 구문을 작성할 필요가 없습니다.

은 간단하게 다음과 같이 호출이 이벤트에 링크 $('.yourClass').trigger('myEvent');

즉, .bind() 통해 수행 할 수 있습니다. $('.yourClass').bind('myEvent', function() { });

0

fling plugin을 사용하면 맞춤 이벤트를 발생시키고 이에 대한 수신기를 연결할 수 있습니다.

$(yourinput).blur(function(){ 
    if(....your condition....) 
     $.fling('publish','YourEventName',your data in json); 
} 

가 리스너를 연결하려면 : 코드는 어떤 모양을

$.fling('subscribe','YourEventName', function(){ 
}); 
관련 문제