Colorbox未正确触发“Uncaught TypeError:Object [object Object]没有方法'colorbox'”

时间:2012-10-08 22:32:24

标签: jquery html css colorbox

我已将所有正确的文件放入,并且js和css正确链接,但我的颜色框似乎不起作用。控制台中的错误是:

Uncaught TypeError: Object [object Object] has no method 'colorbox'

在头文字中链接(这是正确的):

<!--ColorBox -->
<link rel="stylesheet" href="css/colorbox.css" />
    <script src="js/jquery.colorbox.js"></script>
    <script>
      $(document).ready(function(){
        //Examples of how to assign the ColorBox event to elements
        $(".group1").colorbox({rel:'group1'});
        $(".group2").colorbox({rel:'group2', transition:"fade"});
        $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
        $(".group4").colorbox({rel:'group4', slideshow:true});
        $(".ajax").colorbox();
        $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
        $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
        $(".inline").colorbox({inline:true, width:"50%"});
        $(".callbacks").colorbox({
          onOpen:function(){ alert('onOpen: colorbox is about to open'); },
          onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
          onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
          onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
          onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
        });

        //Example of preserving a JavaScript event for inline calls.
        $("#click").click(function(){ 
          $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
          return false;
        });
      });
    </script>
<!-- End ColorBox -->

有人可以帮忙吗?有一个实例here

单击“注册”按钮时,颜色框应该启动。

2 个答案:

答案 0 :(得分:2)

脚本有问题。你有两个额外的“})”集。像这样删除它们:

<script>
  $(document).ready(function(){
    $(".callbacks").colorbox({
      inline:true,
      onOpen:function(){ alert('onOpen: colorbox is about to open'); },
      onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
      onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
      onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
      onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
    });

    //Example of preserving a JavaScript event for inline calls.
    $("#click").click(function(){ 
      $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
      return false;
    });
  });
</script>

让自己成为一名代码折叠的编辑器,这样你就可以直观地看到这些错误。

另外,不要将JS加载到头部;这是一个性能打击。 http://developer.yahoo.com/performance/rules.html#js_bottom

答案 1 :(得分:0)

修复http://www.rubytuesdaycreative.co.uk/testsite/src/jquery.countdown2.js

中的语法错误

Uncaught SyntaxError: Unexpected token }

其他一切看起来都不错