1

我从http://tooltipsy.com/下载了 tooltipsy.min.js并将其放在与我的 html 文件相同的文件夹中。这是我的代码,它根本不起作用。为什么?包装 jquery 代码$(document).ready()没有帮助。

<html>
<head>
<style>
.tooltipsy {
    padding: 10px;
    max-width: 200px;
    color: #303030;
    background-color: #f5f5b5;
    border: 1px solid #deca7e;
}
</style>
<script type="text/javascript" src="jquery-3.1.1.slim.min.js"></script>
<script type="text/javascript" src="tooltipsy.min.js"></script>

<script type="text/javascript">
$('.hastip').tooltipsy();
</script>

</head>

<body>
<a class="hastip" title="I am the tooltip text">I want a tooltip</a>
</body>

</html>
4

1 回答 1

0

这似乎对我有用:

必须添加<p>标签才能将身体向下推,您可以看到提示。

HTML:

<html>
<head>
<style>
.tooltipsy {
    padding: 10px;
    max-width: 200px;
    color: #303030;
    background-color: #f5f5b5;
    border: 1px solid #deca7e;
}
</style>

<script   src="http://code.jquery.com/jquery-3.1.1.min.js"   integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="   crossorigin="anonymous"></script>

<script type="text/javascript">
$(document).ready(function () {
    $('.hastip').tooltipsy();
})

</script>

</head>

<body>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
<a class="hastip" title="Show me">Why don't you work</a>
</body>

</html>

注意:我使用了 jQuery 的 non-slim 版本,因为这个版本的 Tipsy 似乎不能很好地与 jQuery 的 3.x slim 版本配合使用。(在苗条的 jQuery 中使用 Tipsy 会Uncaught TypeError: b.bind is not a function在控制台中引发错误。)

于 2016-10-09T14:05:12.947 回答