我已经检查了jQuery和colorbox脚本是否都已加载,以及它们是否都已正确加载(我使用.getScript查看colorbox是否正确加载并得到肯定的结果)。然而,该函数不会加载colorbox,Firebug会说"$(...).colorbox不是一个函数“。代码过去是可以工作的,但我不确定我做了什么才能破解它。这是标题:
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="colorbox.css"/>
<script src="Scripts/jquery.colorbox.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="Scripts/scripts.js"></script>
<script>
$(document).ready(function(){
$(".popup").colorbox({transition: "elastic", opacity: 0.5, speed: 350});
var panels = $('.accordionButton > .accordionContent').hide();
$("div.accordionButton").click(function(){
panels.slideUp();
$(this).parent().next().slideDown();
return false
});
});
</script>
</head>我已经检查了几次,以确保脚本位于正确的目录中。链接如下:
<div id='supermenu'><table><tr><td><a href='login.php?lang=en' class='popup'>Login</a></td><td> or </td><td><a href='register.php?lang=en'> Register </a></tr></td></table></div>发布于 2013-12-30 03:05:17
您需要在jquery文件之后引用colorbox文件。如下所示:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="Scripts/jquery.colorbox.js"></script>
<script src="Scripts/scripts.js"></script>顺便说一句,这是大多数jquery插件的情况。
发布于 2014-03-30 21:50:02
我在Chrome浏览器中也出现了同样的错误。
如果上面的解决方案没有帮助,#MannyFleurmond解决方案在我的情况下有帮助。尝试使用function($)来修改colorbox js调用:
(function($) {
// Inside of this function, $() will work as an alias for jQuery()
// and other libraries also using $ will not be accessible under this shortcut
})(jQuery);因此,我的ColorBox调用如下所示:
(function ($) {
$('#myelement').click(function (e) {
e.preventDefault();
var url = $(this).attr('href');
$.colorbox({ href: url, width: 936, height: 582, top: 160});
});
})(jQuery);https://stackoverflow.com/questions/20828916
复制相似问题