2009-08-24 6 views
0

특정 클래스의 레이블을 클릭 할 때 나타나는 '도움말'툴팁이 나타나려고합니다. 멀리 클릭하면 사라집니다. 아무것도 나타나지 않습니다. 파이어 버그에서 중단 점을 설정하고 '로딩'툴팁을 볼 수 있습니다. 그러면 아약스가 툴팁을 올바르게 반환 할 때 removeTooltip이 팬텀이라고합니다 (스택 트레이스는 jquery에서 F()라고 말합니다). 그래서 툴팁은 너무 빨리 빠져 나와 결코 보지 못합니다.javascript WTF, 팬텀 함수 호출

HelpText.removeTooltip = function() { 
    $('#activeHelpTip').remove(); 
    $('body').unbind('click', HelpText.removeTooltip); 
} 

HelpText.initToolTip = function(clickedElement) { 
    $('body').click(HelpText.removeTooltip); 
    $(clickedElement).append('<span id="activeHelpTip" class="helpTip">Loading help...</span>'); 
} 

HelpText.updateTooltip = function(helpString, clickedElement, methodName) { 
    if (helpString == null) { helpString = "Help text has not been defined for selected field"; } 
    $('#activeHelpTip').html(helpString); 
} 

$(document).ready(function() { 
    $('.helpText').click(function() { 
     var helpRequested = $(this).html(); 
     var path = window.location.pathname; 
     var fullPage = path.substring(path.lastIndexOf('/') + 1); 
     var page = fullPage.substring(0, fullPage.indexOf('.')); 
     var label_helpRequested = $(this).html(); 

     HelpText.initToolTip(this); 
     HelpText.getHelpText(page, label_helpRequested, this); 
    }); 

HelpText.getHelpText = function(pageNameParam, fieldNameParam, element) { 
    var params = { pageName: pageNameParam, fieldName: fieldNameParam }; 

    if (this._webRequest) { 
     // abort the previous web service call if we 
     // are issuing a new one and the previous one is 
     // active. 
     this._webRequest.get_executor().abort(); 
     this._webRequest = null; 
    } 
    // this._webRequest is a handler on the async request 
    this._webRequest = Sys.Net.WebServiceProxy.invoke(HelpTextServiceURL, 
               "GetHelpText", 
               false, /* use GET */ 
               params, /* parameters to the Ajax service method - case and type sensitive */ 
               HelpText.updateTooltip, /* success callback */ 
               null, /* failure callback */ 
               element); /* user context - preserved info - accessed in the success callback - in this case will contain SPAN */ 
} 

답변

2

귀하의 initToolTip 기능은 removeToolTip()를 호출하는 페이지의 몸 전체에 대한 온 - 클릭 핸들러를 설정합니다. 클릭 이벤트가 $('.helpText')에 발생하면 툴팁이 추가 된 다음 클릭 이벤트가 body 요소 인 removeToolTip()이 호출 될 때까지 버블 링됩니다.

+0

선택기 $ ('body : not (.helpText)')를 사용해 보았습니다. click (HelpText.removeTooltip); 문제를 해결하지 못했습니다. –

+0

''를 사용하지 않으면 상황이 바뀌지 않습니다. – hobbs

1

당신은 툴팁을 보여주는 이벤트에서 버블 링을 취소하지 않았으며 가장 먼저 할 일은 바디에 제거 핸들러를 연결하는 것입니다. 그래서 당신의 init 핸들러가 끝날 때, jQuery와 브라우저는 그 핸들러를 보여주고 처리하는 체인 위로 이벤트를 위임합니다.

해결책은 초기화 핸들러에서 버블 링을 취소하는 것입니다.

+0

레코드에 대해 내 처리기에서 false를 반환하여이 작업을 수행했습니다. –

관련 문제