当我将 jquery-ui 库添加到加载的脚本时,出现“无法在初始化之前在工具提示上调用方法”错误。没有它,一切正常。
这可能是什么原因?
错误:
Uncaught Error: cannot call methods on tooltip prior to initialization; attempted to call method 'show'
n.extend.error @ jquery.min.js:2
(anonymous function) @ jquery-ui.min.js:6
n.extend.each @ jquery.min.js:2
n.fn.n.each @ jquery.min.js:2
e.fn.(anonymous function) @ jquery-ui.min.js:6
(anonymous function) @ scrolltop.js:20
i @ jquery.min.js:2
j.fireWith @ jquery.min.js:2
n.extend.ready @ jquery.min.js:2J @ jquery.min.js:2
我在页面底部加载的脚本是:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="{{ asset('assets/js/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/vendors/livicons/minified/raphael-min.js') }}"></script>
<script src="{{ asset('assets/vendors/livicons/minified/livicons-1.4.min.js') }}"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> //If I remove this everything works fine.
<script type="text/javascript" src="{{ asset('assets/js/frontend/scrolltop.js') }}"></script>//If I remove this but and keep jqueryui I also dont get error.
我的 scrolltop.js 代码是:
$(document).ready(function(){
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-to-top').click(function () {
$('#back-to-top').tooltip('hide');
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
$('#back-to-top').tooltip('show'); //This is the line that seems to trigger the error.
});
$(document).ready(function() {
$(".dropdown").hover(
function() {
$('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideDown("fast");
$(this).toggleClass('open');
},
function() {
$('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideUp("fast");
$(this).toggleClass('open');
}
);
});
最佳答案
我遇到了同样的问题,这是我获得脚本的顺序。 这对我有用。
<script src="~/Scripts/jquery-3.1.0.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
关于javascript - 当我添加 jquery-ui 库时出现“初始化前无法在工具提示上调用方法”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35690989/