javascript 未捕获的类型错误:$(...).tooltip 不是函数错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34290847/
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
Uncaught TypeError: $(...).tooltip is not a function error
提问by
I'm trying to use this code with those tooltips. In this link: Code with tooltip. In fact I just copied the whole code but it's now working.
I get an error that says Uncaught TypeError: $(...).tooltip is not a function error
:
我正在尝试将此代码与这些工具提示一起使用。在此链接中:带有工具提示的代码。事实上,我只是复制了整个代码,但它现在可以工作了。我收到一条错误消息Uncaught TypeError: $(...).tooltip is not a function error
:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$(document).tooltip({
position: {
my: "center bottom-20",
at: "center top",
using: function(position, feedback) {
$(this).css(position);
$("<div>")
.addClass("arrow")
.addClass(feedback.vertical)
.addClass(feedback.horizontal)
.appendTo(this);
}
}
});
});
</script>
What is missing here?
这里缺少什么?
Edit:
编辑:
<script>
jQuery( document ).ready(function( $ ) {
$('.hasTooltip').tooltip();
});
</script>
Using it like this, solved my problem!
像这样使用它,解决了我的问题!
回答by Henrique M.
You are including two times the jQuery UI for different versions. This might be causing conflicts. Try removing
您为不同版本包含了两倍的 jQuery UI。这可能会导致冲突。尝试删除
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
回答by Alaa
You are getting the error because jquery-ui is loaded after your script is executed. you can try to add type="text/javascript" to your scripts normally this must resolve the issue or you must wait until the script is loaded to execute your tooltip. so you must creat a function that will execute your script after the jquery-ui is loaded.
您收到错误是因为在执行脚本后加载了 jquery-ui。您可以尝试将 type="text/javascript" 添加到您的脚本中,通常这必须解决问题,或者您必须等到脚本加载后才能执行您的工具提示。因此您必须创建一个函数,该函数将在加载 jquery-ui 后执行您的脚本。