Javascript $(...).popover 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29910823/
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-23 04:18:01  来源:igfitidea点击:

$(...).popover is not a function

javascriptjquerytwitter-bootstrap

提问by Serguei Fedorov

I have looked through quite a few posts on here dealing with this issue, but none of them seem to solve my problem.

我已经浏览了很多关于这里处理这个问题的帖子,但它们似乎都没有解决我的问题。

I have imported the jQuery and Bootstrap js files in the right order. Things such as bootstrap panels are working perfectly fine for me.

我已经按正确的顺序导入了 jQuery 和 Bootstrap js 文件。诸如引导面板之类的东西对我来说非常好。

My script imports are like this:

我的脚本导入是这样的:

   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
   <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">

However, when I try

但是,当我尝试

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

I get the following message in the Chrome console:

我在 Chrome 控制台中收到以下消息:

 Uncaught TypeError: $(...).popover is not a function

At first I thought maybe popover was not being included in CDN's copy, so I went ahead and downloaded a local copy with all the plugins included from here:

起初我认为可能 popover 没有包含在 CDN 的副本中,所以我继续下载了一个本地副本,其中包含所有插件:

http://getbootstrap.com/customize/

and got the same error message (re-pointed the script tags towards the local js file).

并得到相同的错误消息(将脚本标签重新指向本地 js 文件)。

Doing a search for "popover" the bootstrap.min.js file:

在 bootstrap.min.js 文件中搜索“popover”:

http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js

Shows that popover is included in the file.

显示 popover 包含在文件中。

回答by Arun P Johny

Since you have stated you have included jQuery and the other libraries correctly, 1 possible case is there could be multiple instances of jQuery in the page.

由于您已声明您已正确包含 jQuery 和其他库,因此一种可能的情况是页面中可能有多个 jQuery 实例。

So based on the server technology used, search for a duplicate version of jQuery and if there is any remove them(if not needed else will have to think about noConflict()use).

因此,基于所使用的服务器技术,搜索 jQuery 的重复版本,如果有任何删除它们(如果不需要,则必须考虑使用noConflict())。

In case of duplicate jQuery instances the problem is the jQuery version to which the plugin is attached might be different from the one which you are accessing to use the plugin at that point the plugin will not be found.

如果出现重复的 jQuery 实例,问题是插件所附加的 jQuery 版本可能与您正在访问以使用该插件的版本不同,此时将找不到该插件。

回答by Samir Kulkarni

The order of including bootstrap.js and jquery.js matters. Include the jquery.js BEFORE bootstrap.js

包含 bootstrap.js 和 jquery.js 的顺序很重要。在 bootstrap.js 之前包含 jquery.js

回答by Jukka Newkampton

Had the same problem and checked jquery version. Moving to v1.12 helped me

有同样的问题并检查了 jquery 版本。迁移到 v1.12 对我有帮助