2012-02-22 65 views
2

我對jquery非常陌生,並且遇到了一個bug。每當我將鼠標懸停在我的頁面上的一個按鈕上時,它都會提示一個小工具提示。當我移動鼠標時,它會消失。但是,如果我點擊按鈕,工具提示卡住,我不知道爲什麼。它只是呆在那裏,直到我重新加載頁面。下面是代碼:工具提示疊加在點擊時不會消失

_controls.html.erb優先jQuery的js文件

... 
jQuery.fn.priority = function() 
{ 
    var priority = this; 

    priority.bind('click', function(event) { 
     event.stopPropagation(); 
     priority.selectPriority(); 
    }); 

    priority.bind('unselected', function() { 
     priority.find('a.more').tipsy('hide'); 
    }); 

... 

jQuery.fn.selectPriority = function() 
{ 
    $('.priority.selected').not(this).unselectPriority(); 
    this.addClass('selected'); 
}; 

jQuery.fn.unselectPriority = function() 
{ 
    this.triggerHandler('unselected'); 
    this.removeClass('selected'); 
}; 

爲何按鈕被點擊後提示覆蓋不消失的任何想法的

<%= link_to 'Abandoned', priority, :class => 'abandoned', :'data-status' => 'abandoned', 
          :title => 'Mark as ABANDONED', :rel => 'tipsy' %> 
    <%= link_to 'New', priority, :class => 'new', :'data-status' => 'new', 
          :title => 'Mark as NEW', :rel => 'tipsy' %> 
    <%= link_to 'Started', priority, :class => 'started', :'data-status' => 'started', 
          :title => 'Mark as STARTED', :rel => 'tipsy' %> 
    <%= link_to 'Completed', priority, :class => 'completed', :'data-status' => 'completed', 
          :title => 'Mark as COMPLETED', :rel => 'tipsy' %> 
</div> 

一部分?

PS我沒寫這段代碼我只是想調試它。讓我知道這是不是工具提示所在位置的正確代碼。

更新:工具提示有時會卡住。我刪除了event.stopPropagation();它仍然發生。

回答

0

很難從你提供的代碼片段中知道,但嘗試註釋掉event.stopPropagation();行,看看有什麼。

+0

有沒有其他的東西可以讓我更容易調試?另外,我甚至無法知道代碼中的哪個位置觸發了...我錯過了什麼嗎?我到處看看 – 2012-02-22 18:27:17

2

您可以嘗試取出綁定並直接在事件中調用醉意的隱藏,如下所示:$('#element').tipsy('hide')這可能會幫助您調試它。我在我的一些東西中遇到了同樣的問題,並致電hide解決了這個問題。退房「手動觸發工具提示」酒意頁:http://onehackoranother.com/projects/jquery/tipsy/

另一種選擇是使用delayOut功能的元素,像這樣:

$('.mg-unrd').tipsy({gravity:'s', delayIn: 10, delayOut: 5}); 

的delayOut工作對我來說比隱瞞,這有時候還是給了我鬼魂。

其實,我發現這一點代碼解決了它的適當...在Tipsy.js文件中,在170行左右,我添加了一個mousedown到eventOut,hooray!

//eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'; 
eventOut = options.trigger == 'hover' ? 'mousedown mouseleave' : 'blur';