jQuery 引导程序:未捕获的类型错误:对象 [对象对象] 没有方法“工具提示”、“提前输入”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12764090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:00:49  来源:igfitidea点击:

bootstrap: Uncaught TypeError: Object [object Object] has no method 'tooltip', 'typeahead'

jqueryjquery-uitwitter-bootstrap

提问by DarkKnightFan

I am trying to use the tooltip, typeahead, datepicker features of bootstrap. But I keep getting these errors in the console!

我正在尝试使用引导程序的工具提示、提前输入、日期选择器功能。但是我一直在控制台中收到这些错误!

Uncaught TypeError: Object [object Object] has no method 'tooltip'
Uncaught TypeError: Object [object Object] has no method 'typeahead'

This is how my imports look like:

这是我的导入的样子:

<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/datepicker.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="js/bootstrap-typeahead.js"></script>
<script type="text/javascript" src="js/highcharts.js"></script>
<script type="text/javascript" src="js/exporting.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery.dropdown.css" />
<script type="text/javascript" src="js/jquery.dropdown.js"></script>

Some sample code:

一些示例代码:

<a class="btn btn-success" data-toggle="modal" href="#payments"
           rel="tooltip" data-placement="top" title="Record your payments">
            <i class="icon-check icon-white"></i> Payments</a>

$("#payments").tooltip('show');

Similarly I have code for datepicker and typeahead.

同样,我有 datepicker 和 typeahead 的代码。

any solution?

任何解决方案?

EDIT:

编辑:

This is what I tried just now:

这是我刚才尝试的:

<a href="#" rel="tooltip" data-placement="top" title="Tooltip on top">Test</a>

<script type="text/javascript">
$(function() {
    $("#").tooltip().tooltip('show');
});
</script>

But still no success. It does show the tooltip text when I hover over Testbut the it is of the pre-historic times. Not like the ones shown on bootstrap example pages. Not cool.

但仍然没有成功。当我将鼠标悬停在上面时,它确实显示了工具提示文本,Test但它是史前时代。不像引导程序示例页面上显示的那样。不酷。

So now can anyone tell where am I going wrong?

所以现在谁能告诉我哪里出错了?

采纳答案by Bogdan

Are you sure the bootstrap js files are loaded correctly? And also you should initialize the tooltip plugin on the element before calling the showmethod programmaticaly:

你确定 bootstrap js 文件加载正确吗?而且你应该在以show编程方式调用方法之前初始化元素上的工具提示插件:

<a href="#" rel="tooltip" data-placement="top" title="Tooltip on top">Test</a>

<script type="text/javascript">
$(function() {
    $("a[rel='tooltip']").tooltip();
});
</script>

That applies to datepickerand typeaheadplugins as well.

这也适用于datepickertypeahead插件。

回答by you786

I just ran into this problem and my issue was that I was accidentally including jQuery twice.

我刚遇到这个问题,我的问题是我不小心包含了两次 jQuery。

回答by Johndave Decano

I can see the bootstrap-tooltip.js doesnt exist in your script tags.

我可以看到您的脚本标签中不存在 bootstrap-tooltip.js。

<script src="js/bootstrap-tooltip.js"></script>

回答by user2704238

I would try putting your bootstrap scripts underneath all your other scripts. I had the same problem and it was because I had a jQuery script above my bootstrap script.

我会尝试将您的引导脚本放在所有其他脚本之下。我遇到了同样的问题,这是因为我的引导脚本上方有一个 jQuery 脚本。