2014-09-10 120 views
0

我使用工具提示顯示下面的代碼,點擊事件jQuery的工具提示

HTML組件:

<a href="#" class="tooltip" data-description="Test tooltip">Test</a><br> 

JQuery的:

$(document).on("click", ".tooltip", function() { 
    $(this).tooltip(
     { 
      items: ".tooltip", 
      content: function(){ 
       return $(this).data('description'); 
      }, 
      close: function(event, ui) { 
       var me = this; 
       ui.tooltip.hover(
        function() { 
         $(this).stop(true).fadeTo(400, 1); 
        }, 
        function() { 
         $(this).fadeOut("400", function(){ 
          $(this).remove(); 
         }); 
        } 
       ); 
       ui.tooltip.on("remove", function(){ 
        $(me).tooltip("destroy"); 
       }); 
      } 
     } 
    ); // this is the line i'm getting "Expected Identifier, string or number". 
    $(this).tooltip("open"); 
}); 

我使用jQuery 1.9.1 .js和jquery-ui.1.9.2.js。但我得到「預期標識符,字符串或數字」。

編輯:錯誤已解決,但仍然沒有獲得點擊事件的工具提示。
有人能告訴我我錯了哪裏?

+0

http://stackoverflow.com/editing-help#code – 2014-09-10 21:29:22

+1

工具提示設置對象的'close'函數後面有一個額外的尾隨逗號。 – 2014-09-10 21:32:43

+0

@RoryMcCrossan - 是現在錯誤已解決,但單擊href時不顯示工具提示。 – DeepVeen 2014-09-10 21:44:23

回答

0

此Codepen:http://codepen.io/anon/pen/EjVBOW似乎適用於我的代碼和最新的jQuery和jQuery UI。它爲你解決了嗎?

$(document).on("click", ".tooltip", function() { 
    $(this).tooltip({ 
    items: ".tooltip", 
    content: function() { 
     return $(this).data('description'); 
    }, 
    close: function(event, ui) { 
     var me = this; 
     ui.tooltip.hover(
     function() { 
      $(this).stop(true).fadeTo(400, 1); 
     }, 
     function() { 
      $(this).fadeOut("400", function() { 
      $(this).remove(); 
      }); 
     } 
    ); 
     ui.tooltip.on("remove", function() { 
     $(me).tooltip("destroy"); 
     }); 
    } 
    }); // this is the line i'm getting "Expected Identifier, string or number". 
    $(this).tooltip("open"); 
});