我正在學習 jQuery,但遇到了一個小問題。 當我將 jQuery 代碼直接放在我的 HTML 中的標簽中時,它可以工作,但是當我從不同的文件中導入它時,沒有任何反應。 這些是我在 HTML 中的腳本標簽:
<script type="text/javascript" src="scripts/jquery-1.10.2.js"></script>
<script type="text/javascript" src="scripts/test.js"></script> <!--This is my jQuery code-->
test.js
包含以下代碼:
$(document).ready(function(){
console.log("Hello");
});
當頁面加載時,控制台是空的。 但是,當我這樣粘貼以下代碼時,在我的 html 文檔中,一切正常。
<script>
$(document).ready(function(){
console.log("Hello");
});
</script>