javascript 未捕获的类型错误:$ 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30630839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: $ is not a function
提问by FFlaser
I can't solve this problem where the console gives this error: Uncaught TypeError: $ is not a function
. This is the code it points to:
我解决不了这个问题,在控制台中给出了这样的错误:Uncaught TypeError: $ is not a function
。这是它指向的代码:
<script type="text/javascript">
$(document).ready(function() {
$(".linky").click(function(){
var t = $(this); //<-ERROR POINTS HERE
var y = $("#0"+t.attr("id")).offset().top;
$('html,body').animate({scrollTop: y},500);
});
});
</script>
Any help would be much appreciated!
任何帮助将非常感激!
采纳答案by Allen Tellez
You need to include the jquery script
您需要包含 jquery 脚本
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
回答by Topicus
Maybe jQuery.noConflict();
it's being used somewhere inside your site. Try with this:
也许jQuery.noConflict();
它正在您网站内的某个地方使用。试试这个:
<script type="text/javascript">
(function( $ ) {
$(document).ready(function() {
$(".linky").click(function(){
var t = $(this); //<-ERROR POINTS HERE
var y = $("#0"+t.attr("id")).offset().top;
$('html,body').animate({scrollTop: y},500);
});
});
})(jQuery);
</script>