2011-03-13 34 views
1

我得到的错误:$(’滚动”。)滚动不是一个函数,当我尝试使用滚动

<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> 

可以。任何人看到是什么造成这个?

[编辑]

之后马克·希尔德里斯指出,我用的是已经库捆绑jQuery的,我删除了我的谷歌jQuery的CDN参考(上面没有显示),然后我得到了“$不函数'错误。

我当时就知道的jQuery与flowplay冲突,所以我更新我的网页使用

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

这是温和的打扰,因为我有改剧本在我现有的网页使用jQuery代替$的。

有反正我可以继续使用$,或者我有使用jQuery吗?

+1

运行此确切代码会导致0错误。你的脚本还有什么? – 2011-03-13 18:43:00

+0

我也测试过这个并没有收到错误。 – 2011-03-13 19:24:12

+0

也一样。你能提供更多信息吗?如果缓存损坏,也许尝试Ctr + f5? – Andrew 2011-03-13 20:10:02

回答

0

看着你的代码,我认为你错过了jQuery库。你可以从谷歌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/

+1

我不认为这是问题所在。看起来,jQuery工具库不像一个插件,你需要单独包含jQuery库。请参阅该库的[http://flowplayer.org/tools/download/index.html](下载页面)。 – 2011-03-13 19:06:05

+0

对不起,格式化后无法更改:[下载页面](http://flowplayer.org/tools/download/index.html) – 2011-03-13 19:11:43

0

使用

var $j=jQuery.noConflict(); 

由于JavaScript的也使用$符号,发生冲突。然后,你可以按照如下

$j(document).ready(function()){ 
    // jQuery('#foo) .... etc 
    }); 
+0

这实际上并没有回答这个问题 - 他能做到吗?无需改变他的'$'参考? – 2012-10-28 22:03:22

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);