【问题标题】:jquerytools tooltip filled with ajax用ajax填充的jquerytools工具提示
【发布时间】:2012-06-15 18:14:21
【问题描述】:

我正在尝试将一些内容加载到 jQueryTools 工具提示中,具体取决于触发器父级的元素。现在我被这个困住了:

 <div id="id-1">
      <div>
        <div>
          Bla <a class="trigger">trigger</a>
        </div>
        <div class="tooltip">empty</div>
      </div>
 </div>
 <div id="id-2">
      <div>
        <div>
          Bla <a class="trigger">trigger</a>
        </div>
        <div class="tooltip">empty</div>
      </div>
 </div>

注意:默认情况下,插件会在触发器元素之后加载带有“工具提示”类的 DIV 中的扩展 HTML。

现在,JS 应该告诉我父 DIV ID 的名称并将内容加载到工具提示中,具体取决于该 ID 名称。

jQuery(".tooltip").tooltip({
    onShow: function() {
        var foundId = jQuery(this).parent().parent().attr("id");
                    // generate a url from the result, e.g. exmpl.com/id-1.html
                    // put the url content in the tooltip container
    }
});

我在 JS 方面很垃圾 - 有解决这个问题的方法吗?

【问题讨论】:

  • 我有点不清楚。您想将什么内容准确地加载到工具提示中?

标签: jquery tooltip jquery-tools


【解决方案1】:

这应该可行:

jQuery(".tooltip").tooltip({
    onShow: function() {
        var foundId = jQuery(this).parent().parent().attr("id");
        $.get('/some-url/' + foundId, function(data){
          $(this).html(data);
        });
    }
});

您应该考虑放置一个加载图形或其他东西,让用户知道当他们悬停时正在检索数据。这将使客户端有时间访问服务器以获取您想要的内容。

【讨论】:

  • 好主意。对 Bootstrap 3+ 使用以下内容:$(".tooltip").tooltip().on('shown.bs.tooltip', function() { // the above function; });
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多