twitter-bootstrap Bootstrap .dropdown() “Uncaught TypeError: undefined is not a function”

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

Bootstrap .dropdown() "Uncaught TypeError: undefined is not a function"

javascriptjqueryhtmltwitter-bootstrap

提问by chadb768

I know this question has been asked before, but somehow none of the fixes for other people have worked for me. I have a feeling it has something to do with importing my plugins. When clicking a field in a bootstrap dropdown box I get "undefined is not a function" in the console for this line of code:

我知道以前有人问过这个问题,但不知何故,其他人的修复方法都没有对我有用。我有一种感觉,这与导入我的插件有关。单击引导程序下拉框中的字段时,我在控制台中为这行代码显示“未定义不是函数”:

$target.closest( '.btn-group' )
     .find( '[data-bind="label"]' ).text( $target.text() )
        .end()
     .children( 'dropdown-toggle' ).dropdown('toggle');

Here's my import code in my HTML:

这是我的 HTML 中的导入代码:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="application/javascript" data-main="static/js/main" src="static/js/libs/require/2.1.11/require.js"></script>
<script src="static/js/libs/bootstrap/bootstrap.min.js"></script>
<link href="static/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css">

Whenever I click the dropdown box I also get this error in the "Network" tab of my console, it says that the request was cancelled:

每当我单击下拉框时,我也会在控制台的“网络”选项卡中收到此错误,它表示请求已取消:

file:///home/chad/.config/google-chrome/Default/Extensions/gkojfkhlekighikafcpjkiklfbnlmeio/1.6.222_0/js/jquery.min.map

Any help on this would be greatly appreciated! I've been pulling my hair out over it for hours.

对此的任何帮助将不胜感激!我已经把头发拉出来好几个小时了。

回答by dubonzi

Long shot here, but are you using the chrome extension called "Hola" ? I noticed this message

远射在这里,但您是否使用名为“Hola”的 chrome 扩展?我注意到这条消息

Denying load of chrome-extension://gkojfkhlekighikafcpjkiklfbnlmeio/js/jquery.min.map. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

while testing a web app im developing and found out that it was that extension causing the error, just disabled it and the message didnt appear anymore. Im also using bootstrap, dont know if its related to that.

在测试我正在开发的 Web 应用程序时,发现是该扩展程序导致了错误,只需将其禁用,该消息就不再出现。我也在使用引导程序,不知道是否与此有关。

The code after the "//" is the id of the extension, you can compare it with the ids in the Chrome extension configuration, see this imageand notice the id is the same as in the error.

“//”后面的代码是扩展程序的id,您可以将其与Chrome扩展程序配置中的id进行比较,查看此图片并注意id与错误中的id相同。

Hope this helps.

希望这可以帮助。

回答by Sukima

Maybe your script tags are out of order?

也许你的脚本标签有问题?

<script type="application/javascript" data-main="static/js/main" src="static/js/libs/require/2.1.11/require.js"></script>

Which includes the call for dropdown()is probably being executed before:

其中包括dropdown()之前可能正在执行的调用:

<script src="static/js/libs/bootstrap/bootstrap.min.js"></script>

Which defines the dropdown()method.

其中定义了dropdown()方法。

Does the code in the require app get wrapped in a $(function() {})?

require 应用程序中的代码是否包含在 a 中$(function() {})