2

我收到错误消息:当我尝试使用可滚动时,$(".scrollable").scrollable 不是函数

<html>
<head>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
</head>
<body>
<script>
$(function() {
  // initialize scrollable with mousewheel support
  $(".scrollable").scrollable({ vertical: true, mousewheel: true });
});
</script>
</body>
</html>

谁能看到是什么原因造成的?

[编辑]

在 Mark Hildreth 指出我使用的库已经捆绑了 jQuery 之后,我删除了我的 Google jQuery CDN 参考(上面未显示),然后我得到了“$ 不是函数”错误。

那时我知道 jQuery 与 flowplay 发生冲突,所以我更新了我的页面以使用

jQuery.noConflict();
jQuery(document).ready(function()){
   // jQuery('#foo) .... etc
});

这有点烦人,因为我必须更改现有页面中的脚本以使用 jQuery 而不是 $。

无论如何我可以继续使用$,还是我必须使用jQuery?

4

4 回答 4

1
// you don't have to use jQuery(document).ready(function()){});
// or noConflict

$ = null; // doean't matter here what happens to $

// just wrap your jQuery code passing in jQuery...
(function ($) {
    //write jQuery here...
    $(".scrollable").scrollable({
        vertical: true,
        mousewheel: true
    });
})(jQuery);
于 2012-09-19T16:42:33.627 回答
0

利用

    var $j=jQuery.noConflict();

由于 javascript 也使用 $ 符号,因此会出现冲突。然后你可以编写如下代码

    $j(document).ready(function()){
    // jQuery('#foo) .... etc
    });
于 2012-04-27T07:33:49.450 回答
0

查看您的代码,我认为您缺少 jQuery 库。您可以从 google cdn 中包含它。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

来源: http ://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

于 2011-03-13T18:52:49.930 回答
0

如果您在代码中包含http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js,那么您需要编写 jQuery.noConflict();

于 2012-12-12T06:32:32.877 回答