<script type="text/javascript" href="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/stylesheets/style.css">在页面的末尾,有以下脚本:
案例1:没有错误,但是控制台上没有打印出"hello“
<script>
(function() {
console.log("hello");
});
</script>案例2:我得到了一个错误:“未定义的ReferenceError:$”
<script>
$(document).ready(function() {
console.log("hello");
});
</script>你能告诉我为什么我会犯这些错误吗?谢谢
发布于 2014-02-03 08:40:11
您必须在src标记中使用href而不是href。
发布于 2014-02-03 08:40:21
案例1:您正在定义函数,但从不调用它。您需要在表达式后面加上一对括号:
(function() {
console.log("hello");
})();案例2:<script>标记的正确语法是src=URL,而不是href=URL。
发布于 2014-02-03 08:41:53
将href更改为src
在js中,我们使用src,在css中我们使用href。
<script type="text/javascript" href="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>改为
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>https://stackoverflow.com/questions/21522779
复制相似问题