jla*_*i79 -1 javascript jquery
我有一个问题,包括我的网页中的jQuery脚本.我总是在第6行中得到错误"$ is not a function".我将脚本简化为以下非常简单的:
$(document).ready(function(){
myTest();
});
function myTest(){
window.console && console.log($("#test"));
}
Run Code Online (Sandbox Code Playgroud)
为什么第6行出现错误?为什么不在第1行呢?
您尚未包含jquery.js在您的页面中,或者您使用的路径不正确.以下是使用Google的CDN的示例:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
// your code here...
</script>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
浏览器错误消息中给出的行号是众所周知的不可靠的,总是使用实际的错误消息作为问题的指南.