JQuery UI 工具提示 - 工具提示的位置错误(位于页面左侧而不是按钮周围)

Rad*_*ski 2 javascript jquery jquery-ui tooltip jquery-ui-tooltip

我有这段代码:

<!DOCTYPE html>
<HTML>
<HEAD>
    <TITLE>My first HTML document</TITLE>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<link rel="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

<script>

    $(document).ready(function(){
        $(".has-tooltip").each(function(){
            $(this).tooltip({content: "test", items: "button"});
        });
    });

</script>
</HEAD>
<BODY>
    <BUTTON class="has-tooltip" style="margin-left: 100px;">First</BUTTON>
    <BUTTON class="has-tooltip" style="margin-left: 200px;">Second</BUTTON>

</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

工具提示完全错误 - 它应该以 jQuery UI 的样式出现,但它没有,而且位置错误 - 即使对于具有较大边距的按钮,它也会出现在屏幕的左侧(正如我所说,没有任何样式,它看起来像纯文本),即使将 ,,track" 属性设置为 ,,true" 它也不会完全跟随光标,但仍然出现在页面的左侧,并且当我移动光标时会移动一点。我认为这是非常简单的示例(该代码是我工作中发生的简化问题),我看不出我做错了什么。如果有人帮助我,我会很高兴 - 提前谢谢你。

PS 片段,这与我在浏览器中得到的行为完全相同:

<!DOCTYPE html>
<HTML>
<HEAD>
    <TITLE>My first HTML document</TITLE>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<link rel="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

<script>

    $(document).ready(function(){
        $(".has-tooltip").each(function(){
            $(this).tooltip({content: "test", items: "button"});
        });
    });

</script>
</HEAD>
<BODY>
    <BUTTON class="has-tooltip" style="margin-left: 100px;">First</BUTTON>
    <BUTTON class="has-tooltip" style="margin-left: 200px;">Second</BUTTON>

</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

小智 6

您没有正确链接到 css 文件。

代替:

<link rel="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

和:

<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">