简体   繁体   English

Bootstrap 3工具提示不起作用

[英]Bootstrap 3 tooltip not working

Following a really outdated bootstrap tutorial, but it is really well structured so trying to finish the course.遵循一个非常过时的引导教程,但它的结构非常好,因此试图完成课程。 I have been able to fix most of the issues by looking at bootstrap documentation, and I am a bit stuck on making the tooltip work on the main index.php page.通过查看引导文档,我已经能够解决大部分问题,并且我有点坚持让工具提示在主 index.php 页面上工作。 Bare in mind, I am new to web dev.请记住,我是网络开发的新手。

I can get the tooltip to work if the script is on the same php file.如果脚本在同一个 php 文件上,我可以让工具提示工作。 As shown below:如下所示:

<script>
    $(document).ready(function(){
        $('[data-toggle="tooltip"]').tooltip();
    });
</script> 

Inside the body:体内:

<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip : left">Tooltip : Left</button>

However if I remove the script from index.php, and place it inside myscript.js.但是,如果我从 index.php 中删除脚本,并将其放在 myscript.js 中。 It won't work, I've tried different ways and search through SO tried just about every suggestion in the past and nothing seems to work.它行不通,我尝试了不同的方法并搜索了过去几乎所有的建议,但似乎没有任何效果。 I know that myscript.js is being loaded because I have another function there for hovering over a menu dropdown, also no errors on the console.我知道 myscript.js 正在加载,因为我有另一个功能可以将鼠标悬停在菜单下拉菜单上,控制台上也没有错误。

Inside myscript.js在 myscript.js 中

$("[data-toggle='tooltip']").tooltip();  

I've also tried this:我也试过这个:

$(document).ready(function() {
    $("body").tooltip({ selector: '[data-toggle=tooltip]' });
});

Any suggestions as to why is not working?关于为什么不起作用的任何建议?

The code is ok, I don't know your bootstrap version and how you setup so I could guess that could be the problem. 代码还可以,我不知道你的bootstrap版本以及你如何设置所以我猜可能是问题所在。

Also, you try to add a left tooltip, but you need some space for it to show so check the following example. 此外,您尝试添加left工具提示,但需要一些空间才能显示,因此请查看以下示例。

 $(document).ready(function() { $('[data-toggle="tooltip"]').tooltip(); }); 
 #mybtn { margin-left: 200px; margin-top: 100px; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <button id="mybtn" type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip : left">Tooltip : Left</button> 

The correct answer for this issue was chrome cache. 这个问题的正确答案是chrome缓存。 I use dev tools to disable the cache. 我使用开发工具来禁用缓存。 Disabling Chrome cache for website development I found out when I stumbled across another issue. 禁用Chrome缓存以进行网站开发我偶然发现了另一个问题。

If you're using jquery ui, then load the scripts in following order.如果您使用的是 jquery ui,请按以下顺序加载脚本。

<script src="/jquery.js"></script>
<script src="/jquery-min.js"></script>
<script src="/bootstrap.js"></script>

In my case, it simply worked when I put the jquery link in the head tag instead of the body tag.就我而言,当我将 jquery 链接放在 head 标签而不是 body 标签中时,它就可以正常工作。 Probably because of how the js loads.可能是因为 js 的加载方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM