jQuery和Colorbox"不是一个函数"

Bar*_*der 2 html css jquery colorbox

我一直在努力将Colorbox(一个灯箱替代品)集成到一个站点中.

好的,所以我的头文件是:

<head>
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<link type="text/css" media="screen" rel="stylesheet" href="../colorbox/colorbox.css" />
<script type="text/javascript" src="../colorbox/jquery.colorbox.js"></script>
<script type="text/javascript">
    function saveToBook() { 
        $.fn.colorbox({inline:false, href:'../index.html'}); 
    };
</script>
</head>
Run Code Online (Sandbox Code Playgroud)

我的链接如下:

<a href="#save-to-book" onclick="javascript:parent.saveToBook();return false;" class="recipe-links">Save to Cookbook</a>
Run Code Online (Sandbox Code Playgroud)

我收到的唯一输出(来自FireBug)是:

$.fn.colorbox is not a function
Run Code Online (Sandbox Code Playgroud)

Nic*_*ver 7

我最好的猜测是,这../colorbox/jquery.colorbox.js不是正确的道路,你确定它不是这样的吗?

<script type="text/javascript" src="js/colorbox/jquery.colorbox.js"></script>
Run Code Online (Sandbox Code Playgroud)

此外,您的脚本应该更像这样:

$(function() {
  $("a[href='#save-to-book']").click(function() {
    $(this).parent().colorbox({inline:false, href:'../index.html'});
    return false;
  });
});
Run Code Online (Sandbox Code Playgroud)

只需删除当前函数和onclick锚本身.