Jquery for Tooltip

时间:2014-09-10 21:27:13

标签: javascript jquery html jquery-ui-tooltip

我正在使用以下代码进行点击事件的工具提示显示

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。但我得到“预期标识符,字符串或数字”。

编辑:错误已解决,但我仍未获得点击事件的工具提示。
有人可以告诉我哪里出错了吗?

1 个答案:

答案 0 :(得分: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");
});
相关问题