jQueryは外部スクリプトとしてロードされるため、jsファイルにインクルードする必要があります。Uncaught ReferenceError:jQueryがコンソールでも動作していても定義されていません。
はここに私のコードです:
function addjQuery() {
if (!window.jQuery) {
var jq = document.createElement("script");
jq.type = "text/javascript";
jq.src = "https://code.jquery.com/jquery-3.2.1.min.js";
document.getElementsByTagName("head")[0].appendChild(jq);
console.log("Added jQuery!");
} else {
console.log("jQuery already exists.")
}
}
addjQuery();
jQuery(function($) {
$(document).ready(function() {
});
});
しかし、エラーが発生します。 キャッチされないにReferenceError:私はクロームのdevのツールのコンソールで "jQueryの" または "$" を実行した場合でもjQueryの
が定義されていません、それは働いている。
問題が何ですか?
jQueryの()関数は、前に実行されていますライブラリをロードする – hackerrdave