【问题标题】:Jquery Tooltipster function to show the content when user hovers over it [closed]Jquery Tooltipster 功能可在用户将鼠标悬停在内容上时显示内容[关闭]
【发布时间】:2014-06-04 08:48:11
【问题描述】:

我是 Tooltipster 功能的初学者 以下是我的代码:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>attr demo</title>
  <style>

  div {
    color: red;
    font-size: 24px;
  }

  </style>
  <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
  <script type="text/javascript" src="js/jquery.tooltipster.min.js"></script>
   <script>
        $(document).ready(function() {
            $('.tooltip').tooltipster();
        });
    </script>
</head>
<body>

<div id="my-tooltip"> 
        This div has a tooltip with HTML when you hover over it!
</div>
    <script>

        $(document).ready(function() {
            $( ".my-tooltip" ).tooltip({ content: "Awesome title!" });
            alert("dsad");
        });
    </script>
</body>
</html>

但是输出只显示这个:

当您将鼠标悬停在该 div 上时,它会显示带有 HTML 的工具提示!

同样在控制台中,第 30 行有错误:$( ".my-tooltip" ).tooltip({ content: "Awesome title!" }); Uncaught TypeError: undefined is not a function

请帮忙!!!如何使用工具提示功能并使用它们..?

【问题讨论】:

  • 问题中的笑脸,srsly?

标签: jquery tooltip tooltipster


【解决方案1】:

检查这个Demo Fiddle

$(document).ready(function() {
        $('#my-tooltip').tooltipster({
            content: $('<strong class="tooltip">Awesome title!</strong>')
        });
});

作为替代方案,Jquery UI 还支持 .tooltip()。它易于使用。 在这种情况下,

$( ".selector" ).tooltip({ content: "Awesome title!" }); 

可以,但您必须包含 jQuery UI。

【讨论】:

  • 你能告诉我如何在我的 html 代码中包含 jQuery UI 吗?
  • 就像你包含 jquery &lt;script&gt;- jQueryUI download&lt;script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"&gt;&lt;/script&gt;
  • 好的,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-20
  • 1970-01-01
  • 2018-04-06
  • 2020-08-11
  • 1970-01-01
相关资源
最近更新 更多