【问题标题】:jquery tooltip doesn't display content on hoverjquery 工具提示在悬停时不显示内容
【发布时间】:2019-05-03 14:14:03
【问题描述】:

我正在尝试将table 显示为tooltip 内容。

但是表格似乎没有显示。

这是 HTML:

<td>
    <a href="javascript:void(0);" data-toggle="tooltip1" class="red-tooltip" title="">5 Users</a>
</td>

桌子:

<table id="tooltipContent" border="4" bordercolor="black" cellspacing="1" cellpadding="15px" style="width: 800px; display: none;">
     <tr><td>ravi_shrestha(r_sth@gmail.com)</td></tr>
     <tr><td>ravi_shrestha(r_sth@gmail.com)</td></tr>
     <tr><td>ravi_shrestha(r_sth@gmail.com)</td></tr>
</table>

工具提示初始化:

"fnDrawCallback": function( settings ) {
    $('[data-toggle="tooltip1"]').tooltip({
         content: $('#tooltipContent').html()
    });                
 },

title 属性中添加一些东西是可行的。

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-tooltip


    【解决方案1】:

    尝试使用回调函数,正确添加js和css依赖

    $('[data-toggle="tooltip1"]').tooltip({
             content: function() { return $('#tooltipContent').html();}
    });  
    

    $('[data-toggle="tooltip1"]').tooltip({
      content: function() {
        return $('#tooltipContent').html();
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <td>
      <a href="javascript:void(0);" data-toggle="tooltip1" class="red-tooltip" title="">5 Users</a>
    </td>
    
    <table id="tooltipContent" border="4" bordercolor="black" cellspacing="1" cellpadding="15px" style="width: 800px; display: none;">
      <tr>
        <td>ravi_shrestha(r_sth@gmail.com)</td>
      </tr>
      <tr>
        <td>ravi_shrestha(r_sth@gmail.com)</td>
      </tr>
      <tr>
        <td>ravi_shrestha(r_sth@gmail.com)</td>
      </tr>
    </table>

    【讨论】:

    • 在 sn-p 中工作,你有任何控制台错误吗?
    • no.. 控制台是空的.. 虽然它在 sn-p 中工作.. 令人惊讶..
    • 这意味着代码没有被调用或者你的代码中有一些冲突
    • 我们也必须注入jquery-ui.cssjquery-ui.js吗?
    • 据我所知是的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多